简体   繁体   中英

How to get directory from .jar file into File object?

I have a .jar file and at root of them located a folder. How I can read this folder into java File class?

You can't use File, since this file does not exist independently on the file system. Instead you need getResourceAsStream() to get the contents of the folder, like this:

InputStream in = getClass().getResourceAsStream("/FILENAME.TXT");
BufferedReader input = new BufferedReader(new InputStreamReader(in));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM