Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent to FileInputStream in J2ME?

Is there any equivalent to FileInputStream in J2ME?

like image 323
Abhishek Avatar asked Jun 15 '11 05:06

Abhishek


1 Answers

You should use FileConnection from JSR 75. Here is a short example of using file connection for reading file:

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

Please take a look here for more info.

like image 161
AlexR Avatar answered Sep 28 '22 15:09

AlexR