5

FileInputStreamJ2MEに相当するものはありますか?

4

3 に答える 3

9

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) {
   }
}

詳しくはこちらをご覧ください。

于 2011-06-15T07:13:14.523 に答える
2

同意すると、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

于 2011-06-15T10:13:15.013 に答える
1

JAR ファイル内のファイルのみに関心がある場合は、getResourceAsStream メソッドを参照してください。デバイスで JSR 75 を使用する必要はありません。

于 2012-07-11T04:46:58.533 に答える