问题描述
|
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。