简体   繁体   English

Java无法在CentOS 6.5中打开文件

[英]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. 我正在尝试运行一个Java命令提示符程序,该程序接收5GB csv文件的路径。 While the path is guaranteed to be the right one and I'm running the program as root my program throws: 虽然路径肯定是正确的,但我以root身份运行程序,但程序却抛出了该错误:

 (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: Java行是:

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. 然后我以为可能是文件大小,所以我创建了一个4字符文件。 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. 我修改了Java程序以列出所有接收参数,并正确显示了它们。

I was running the program through a shell script launch.sh with the following content: 我正在通过具有以下内容的shell脚本launch.sh运行该程序:

#!/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. 当我直接使用Java运行它时,它起作用了:找到了文件。

The greatest mistery is that the cmd line params displayed correctly in both situations. 最大的麻烦是在两种情况下cmd线参数均正确显示。 I wonder if shell is actually adding some funny unseen chars to those params. 我不知道shell是否实际上在向这些参数添加了一些有趣的看不见的字符。

As you can see on your file listing, only the root as the right to write on the file. 正如您在文件列表中看到的那样,只有root才具有在文件上写入的权利。 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 : 我认为您的应用程序未以root用户身份运行,因此您应该首先尝试更改文件的权限:

chmod 666 This commande will allow everyone to read and write the files. chmod 666该命令将允许所有人读取和写入文件。

Sincerely, 真诚的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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