JSR 75 (2)
25 April 2008In this post, I will write about how to read a file from the file system of a mobile device.
As you know already, we use JSR 75 optional package (javax.microedition.io.file) to access the files on the mobile device.
After getting the FileConnection, we will use an inputstream to read the contents into a byte array. Once we have all the contents int he byte array, we will display the contents on the console after converting them into String.
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) { } }
Related Posts:
- No related posts
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: JSR 75 (2)