이 문제가 해결되었지만 10 가지 전략이이 문제에 영향을 미치지 않았습니다.Java FileNotFoundException 절대 경로 포함 - 읽기 또는 실행이지만 파일이 존재 함
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()));
EDIT 슬래시와 슬래시를 교체 한 후에, 독자는 여전히 정상적으로 판독 또는 파일을 실행할 수 없다.
LOG : 문자열 인쇄 : 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)
이중 블랙 슬래시로 백 슬래시를 벗어나야합니다. 나는이 코드가 컴파일 에러를 내야한다고 생각한다. – Jens
자바에서는 두 개의 백 슬래시가 필요하다. 문자열 instructions_file = "C : \\ Users \ Anny \\ Dropbox \\ SocialMediaOcto \\ instructions \\ Trees \\ instructions.txt"; –
https://docs.oracle.com/javase/tutorial/essential/io/pathOps.html –