我正在尝试在Java Eclipse中读取文件。系统似乎找不到文件。
这是我的代码:
import java.util.Scanner;
import java.io.*;
public class whyDo {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(new File("c:\\Users\\Vanessa\\Downloads\\CompLet\\CompLet\\sales\\austin.txt"));
System.out.println(input);
// TODO Auto-generated method stub
}
}
运行此代码时,我得到:
Exception in thread "main" java.io.FileNotFoundException: c:\Users\Vanessa\Downloads\CompLet\CompLet\sales\austin.txt (The system cannot find the path specified)
请帮助。预先感谢大家。
由于使用反斜杠,因此可以安全地假定操作系统是Windows的某个版本,因此大小写无关紧要。我建议使用正斜杠(出于可读性),Java可以处理它们。要读取zip文件,请参见Read Content from Files which are inside Zip file。