gpt4 book ai didi

具有绝对路径的 Java FileNotFoundException - 无法读取或执行,但文件存在

转载 作者:行者123 更新时间:2023-11-30 06:08:45 25 4
gpt4 key购买 nike

<分区>

我确定这个问题已经得到解答,但是十种不同的策略都没有解决这个问题。

如果我使用 C:\Users\Anny\Dropbox\SocialMediaOcto\instructions\Trees\instructions.txt作为文件的绝对路径,IDEA 无法从该路径读取或执行。如果我采用相同的路径并将其粘贴到 Windows 资源管理器中,它将立即执行。我不想关注工作目录,因为此文件用作程序的配置文件,但用反斜杠替换斜杠不起作用,绝对路径仍将我带到该文件,但 IDEA 未启动。

我已经无计可施了。

 public static String generateFileName(String folder){

String filename = "";
List<String> hashtags = new ArrayList<>();
String instructions_file = "C:\Users\Anny\Dropbox\SocialMediaOcto\instructions\Trees\instructions.txt";

//does not return true-true, but can launch file on windows explorer..
System.out.println("FILE EXIST AND EXECUTE?" + new File(instructions_file).getAbsoluteFile().canRead() +" "+new File(instructions_file).getAbsoluteFile().canExecute());

System.out.println(new File(instructions_file).getAbsoluteFile());
//C:\Users\Anny\Dropbox\SocialMediaOcto\instructions\Trees\instructions.txt

BufferedReader br = null;

try {

String sCurrentLine;

br = new BufferedReader(new FileReader(new File(instructions_file).getAbsoluteFile()));

编辑将反斜杠替换为正斜杠后,读者仍然无法正常读取或执行文件。

日志:字符串打印: C:/Users/Anny/Dropbox/SocialMediaOcto/instructions/Bees/instructions.txt

  java.io.FileNotFoundException:    C:\Users\Anny\Dropbox\SocialMediaOcto\instructions\Bees\instructions.txt (The system cannot find the file specified)

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com