我已经尝试过这段代码,但总是让我'是'为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();
}
有人知道我做错了吗?
THX!
答案 0 :(得分:2)
试试这个:
InputStream is = getClass().getResourceAsStream("/"+filename);