1

このコードを試してみましたが、常に 'is' が 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();
    }

誰かが私が間違っていることを知っていますか?

どうも!

4

1 に答える 1

2

これを試して:

InputStream is = getClass().getResourceAsStream("/"+filename);
于 2011-11-08T11:05:35.203 に答える