Чтение файла из папки res в J2ME

Я пробовал этот код, но всегда получаю «есть» как NULL. Мой файл находится в папке «res».

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();
    }

Кто-то знает, что я делаю неправильно?

Спасибо!


person vicmonmena    schedule 07.11.2011    source источник
comment
Каково значение имени файла?   -  person Gorkem Ercan    schedule 07.11.2011
comment
Можете ли вы сказать мне filename ?   -  person bharath    schedule 23.11.2011


Ответы (1)


Попробуй это:

InputStream is = getClass().getResourceAsStream("/"+filename);
person Steve O'Connor    schedule 08.11.2011
comment
Ok! попробую, отпишусь о результатах - person vicmonmena; 15.11.2011
comment
Привет! Я пробовал этот код: StringBuffer str = new StringBuffer(); InputStream is = getClass().getResourceAsStream("/"+filename); if(is == null) {..., но всегда возвращает ноль - person vicmonmena; 15.11.2011