【问题标题】:Linux java No such file or directory, java.io.FileNotFoundException:Linux java No such file or directory, java.io.FileNotFoundException:
【发布时间】:2016-01-05 12:36:24
【问题描述】:

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

此代码在一个我无法修改的 jar 文件中抵抗这是代码的 sn-p

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)

【问题讨论】:

  • System.out.println(new File("/home/admin/Downloads/tools/bin/configuration.txt").exists()); 打印什么?
  • 您是否以“管理员”身份运行程序?
  • 它的打印是真的,来自我的新程序
  • 是的,我正在使用管理员帐户

标签: java linux filenotfoundexception file-handling


【解决方案1】:

它与 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

【讨论】:

    猜你喜欢
    • 2023-04-03
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 2016-11-01
    • 2018-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多