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.

then convert inputstream string.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -