如何解决相当于J2ME中的FileInputStream吗?
| J2ME中有等于“ 0”的东西吗?解决方法
您应该使用JSR 75中的FileConnection。这是使用文件连接读取文件的简短示例:
public void showFile(String fileName) {
try {
FileConnection fc = (FileConnection)
Connector.open(\"file:///CFCard/\" + fileName);
if(!fc.exists()) {
throw new IOException(\"File does not exist\");
}
InputStream is = fc.openInputStream();
byte b[] = new byte[1024];
int length = is.read(b,1024);
System.out.println
(\"Content of \"+fileName + \": \"+ new String(b,length));
} catch (Exception e) {
}
}
请在这里查看更多信息。
, 同意,FileConnection及其getInputStream方法将是最接近FileInputStream的方法。这是带有源代码的快速教程:
http://j2mesamples.blogspot.com/2009/02/file-connection-using-j2me-api-jsr-75.html
您将在此页面上找到更多信息:
http://www.developer.nokia.com/Community/Discussion/showthread.php?143733-How-to-test-file-reading-writing-and-web-server-app-in-emulator
, 如果您只关心JAR文件中的文件,请查看getResourceAsStream方法,该设备不需要使用JSR 75。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。