Linux java没有这样的文件或目录,java.io.FileNotFoundException:

时间:2015-10-08 04:11:01

标签: java linux filenotfoundexception file-handling

在Linux系统(RHEL)中使用文件阅读器时,以下语句无法找到该文件,同样的鳕鱼在Windows环境中正常工作。

此代码抵制在一个jar文件中,我无法修改这是代码的片段

String fileInput = System.getProperty("filelocation");
BufferedReader inputReader = new BufferedReader(new FileReader(fileInput));

属性"filelocation"作为

传递
"/home/admin/Downloads/tools/bin/configuration.txt"

"file:///home/admin/Downloads/tools/bin/configuration.txt"

错误日志

(No such file or directory)
java.io.FileNotFoundException: /home/admin/Downloads/tools/bin/configuration.txt 
 (No such file or directory) 
       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) 
       at com.mycode.Config.readAppConfig(config.java:123)

1 个答案:

答案 0 :(得分:0)

这与JAVA无关。它是因为传递变量的shell脚本而来的 使用语句input_file = $ {input_file:0:$(expr $ {#input_file} - 1)}
这个语句用于删除字符串的最后一个字符,在我的例子中,它是一个新的Line char,它是不可见的。

感谢表格:https://unix.stackexchange.com/questions/144298/delete-the-last-character-of-a-string-using-string-manipulation-in-shell-script/144345#144345?newreg=9e4833bcf644426aaf9f275bf4fd1743

相关问题