1

I've tried this code but always get me 'is' as NULL. My file is located at "res" folder.

StringBuffer str = new StringBuffer();
    InputStream is = getClass().getResourceAsStream(filename);
    if(is == null) {
        System.out.println("'is' is null");
    } else {

        InputStreamReader reader = new InputStreamReader(is);

        String line = null;
        // Read a single line from the file. null represents the EOF.
        while ((line = readLine(reader)) != null) {
            // Append the read line to the main form with a linefeed ('\n')
            str.append(line + "\n");
        }
        reader.close();
    }

Someone knows what I'm doing wrong?

Thx!

bharath
  • 14,283
  • 16
  • 57
  • 95
vicmonmena
  • 41
  • 1
  • 2
  • 8

1 Answers1

2

Try this:

InputStream is = getClass().getResourceAsStream("/"+filename);
Stephen O'Connor
  • 1,465
  • 1
  • 10
  • 20
  • Ok! I'll try it I'll feed back with results – vicmonmena Nov 15 '11 at 09:46
  • Hi!I've tried that code: `StringBuffer str = new StringBuffer(); InputStream is = getClass().getResourceAsStream("/"+filename); if(is == null) {...` but always returns null – vicmonmena Nov 15 '11 at 17:44