java - Reading a file from a Res folder -


I have inserted a file "template.html" inside the RAW folder and I want to read it in the inputstream. But it is returning me nonsense. It does not understand what is wrong with the code given below

  The file name passed in the form of the parameter "res / raw / testtemplate.html" public string getFile (string filename) ) {InputStream input = this.getClass () is. GetClassLoader (). GetResourceAsStream (fileName); Return GetStringFromInputStream (Input); }  

In addition, these files can be a better solution by putting them in a particular subfolder and putting it in the Asset folder but then I believe that I have to pass the reference in the Asset Manager. I do not understand the solution, sorry I'm new to Android development.

Edit

I have started implementing this solution with assets.

getFile ("template.html") // I'm sending extensions at this time

> getting the GetAssets error Problem is undefined .

  public string getFile (string filename) {BufferedReader reader = null; Stringbilder sb = new stringbiller (); String line; {Reader = new BufferedReader (try new InputStreamReader (getAssets (.)); While ((line = reader. Readline ())! = Tap) {sb.append (line);}} hold (IOException E) {e.printStackTrace ();} Finally {if (reader! = Null) {try} reader.close ();} hold (IOException e) {e.printStackTrace ();}}} Return sb.toString ( );}  

use this

  New BufferedInputStream (getResources () .openRawResource (filepath));  

This will return a buffer input stream


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -