[英]Linux java No such file or directory, java.io.FileNotFoundException:
While using the File reader in the Linux system(RHEL) the below statements are not able to locate the file, same cod is working fine in Windows env. 在Linux系统(RHEL)中使用文件阅读器时,以下语句无法找到文件,相同的cod在Windows env中可以正常工作。
This code resists in one jar file which I cannot modify this is the snippet of the code 这段代码包含在一个我无法修改的jar文件中,这是该代码段
String fileInput = System.getProperty("filelocation");
BufferedReader inputReader = new BufferedReader(new FileReader(fileInput));
Attribute "filelocation"
is passed as 属性
"filelocation"
方式传递
"/home/admin/Downloads/tools/bin/configuration.txt"
or 要么
"file:///home/admin/Downloads/tools/bin/configuration.txt"
Error log is 错误日志为
(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)
It was not related to JAVA. 它与JAVA无关。 it was coming because of the shell script from where the variable was passed
它是由于传递变量的shell脚本而来的
used the statement input_file=${input_file:0:$(expr ${#input_file} - 1) } 使用语句input_file = $ {input_file:0:$(expr $ {#input_file}-1)}
this statement is used to remove the last character of a string, In my case it was a new Line char, which was not visible. 该语句用于删除字符串的最后一个字符,在我的情况下,这是一个新的Line char,它是不可见的。
thanks to the form : https://unix.stackexchange.com/questions/144298/delete-the-last-character-of-a-string-using-string-manipulation-in-shell-script/144345#144345?newreg=9e4833bcf644426aaf9f275bf4fd1743 感谢表单: https : //unix.stackexchange.com/questions/144298/delete-the-last-character-of-a-string-using-string-manipulation-in-shell-script/144345#144345?newreg = 9e4833bcf644426aaf9f275bf4fd1743
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.