I am trying to read a text file from inside of exectutable jar. I can read it from eclipse, but can not from executable jar.I googled, and found out I have to use getClass.getResource. But all google examples are not for Buffered Reader. My current codes are the following.
BufferedReader in = null;
try
{
File file = new File ("tfl.txt");
in = new BufferedReader(new InputStreamReader( new
FileInputStream(file),"unicode"));
...
}
Try this
InputStream localInputStream = ClassLoader.getSystemClassLoader().getResourceAsStream("resource_name");
BufferedReader br = new BufferedReader(new InputStreamReader(localInputStream));
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.