从J2ME中的res文件夹中读取文件
我已经尝试过这段代码,但总是让我的“是”为空。我的文件位于“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();
}
有人知道我做错了什么吗?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: