简体   繁体   中英

Java can't open file in CentOS 6.5

I'm trying to run a java command prompt program that receives a path to a 5GB csv file. While the path is guaranteed to be the right one and I'm running the program as root my program throws:

 (No such file or directory)ava.io.FileNotFoundException: /data/tmp/NPPES/npidata.csv
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:146)
    at java.io.FileInputStream.<init>(FileInputStream.java:101)
    at java.io.FileReader.<init>(FileReader.java:58)
    ...

the java line is:

BufferedReader file = new BufferedReader( new FileReader(args[1]));

the file listing:

-rw-r--r-- 1 root root          4 Mar 11 15:35 empty.csv
-rw-r--r-- 1 root root 5097950480 Feb 11 00:36 npidata.csv

Then I thought it might be the file size so I created a 4 character file. Still nothing. Has anyone by any chance experienced this before?

Update:

I modified the java program to list all the receiving arguments and they displayed correctly.

I was running the program through a shell script launch.sh with the following content:

#!/bin/sh
#echo on
java -Xmx16000M -XX:MaxPermSize=512M -classpath "../classes:../lib/*" $@

When I ran it directly with java it worked: the file was found.

The greatest mistery is that the cmd line params displayed correctly in both situations. I wonder if shell is actually adding some funny unseen chars to those params.

As you can see on your file listing, only the root as the right to write on the file. Which means also that only the root can open it.

I think your application is not running as root so you should first try to change the right on your files :

chmod 666 This commande will allow everyone to read and write the files.

Sincerely,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM