简体   繁体   中英

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.

This code resists in one jar file which I cannot modify this is the snippet of the code

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

Attribute "filelocation" is passed as

"/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. it was coming because of the shell script from where the variable was passed
used the statement 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.

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

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