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.
我有一个.jar文件,在它们的根目录下有一个文件夹。我如何将此文件夹读入javaFile类?
.jar
File
您不能使用 File,因为该文件在文件系统上并不独立存在。相反,您需要 getResourceAsStream() 来获取文件夹的内容,如下所示:
InputStream in = getClass().getResourceAsStream("/FILENAME.TXT"); BufferedReader input = new BufferedReader(new InputStreamReader(in));