java - 相当于J2ME中的FileInputStream?

标签 java java-me fileinputstream

J2ME 中是否有与 FileInputStream 等价的东西?

最佳答案

您应该使用 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, 0, 1024);
      System.out.println
         ("Content of "+fileName + ": "+ new String(b, 0, length));
   } catch (Exception e) {
   }
}

请看here了解更多信息。

关于java - 相当于J2ME中的FileInputStream?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6353453/

相关文章:

java - 将列表总结为流的限制

java - 为什么 Nashorn 将两个整数相加产生 double?

java - 从服务器下载文件

java - Trove 库是线程安全的吗?

java - 使用 Mockito 模拟 java.nio.file.Files 静态方法

blackberry - 从 AppWorld 更新应用程序后 PersistentStore\PersistentObject 数据是否保留

java - BufferedInputStream 和 java.nio.Buffer 有什么区别?

java - 在 Java try block 中找不到符号

java - 将 .class 文件转换为 .jar 文件的 .java 文件

java - 在 BlackBerry Java 应用程序中压缩文件