java - Call a HTML File From Jar -
im generating report template html file in program. resides in /src/main/resources , name "template.html". im using classloader inside code this:
private string readtemplatefile() { string str = ""; url url = classloader.getsystemresource("template.html"); try { filereader input = new filereader(url.getfile()); bufferedreader bufread = new bufferedreader(input); string line; line = bufread.readline(); str = line; while (line != null) { line = bufread.readline(); str += line + "\n"; } bufread.close(); } catch (ioexception e) { } return str; }
it doing nicely when run code inside ide when make runnable jar it, generating empty report. solution? reading.
if it's in jar, it's no longer file.
use classloader.getresourceasstream() retrieve resource inputstream
.
Comments
Post a Comment