Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用 FileReader 读取文件,但我尝试访问的文件与正在运行的代码位于不同的目录中。有没有办法让 FileReader 读取其他目录中的文件?
如果没有,是否有其他方法可以从不同目录读取文件?
提前致谢
你当然可以
BufferedReader br = new BufferedReader(new FileReader("C:\\test.txt"));
BufferedReader 对路径一无所知。
代码可能如下所示:
BufferedReader br = new BufferedReader(new InputStreamReader(new FIleInputStream("/a/b/c"), "utf-8"));