View RSS Feed

My Java Tips

Reading/writing files

Rate this Entry
by , 11-22-2011 at 06:26 PM (1094 Views)
This post is all about reading and writing text files on mobile device.

In order to write files on the mobile device, you need com.motorola.file.writeaccess. If your application has that permission, you can write files easily using the following code.

Java Code:
FileConnection sc = (FileConnection)"file:///phone/tmp.txt");
OutputStream os = sc.openOutputStream();
os.write(("text to go into the file").getBytes());
com.motorola.file.readaccess is need to read files from mobile device. Files are read byte by byte as shown below.

Java Code:
FileConnection sc = (FileConnection)"file:///phone/tmp.txt");
InputStream is = sc.openInputStream();
StringBuffer sofar = new StringBuffer();
byte c;
while ((c = (byte) != -1)
You may use this code to learn how to read and write from mobile device. Play with this and explore. Its simple and interesting.
Happy codding!!

Submit "Reading/writing files" to Facebook Submit "Reading/writing files" to Digg Submit "Reading/writing files" to Submit "Reading/writing files" to StumbleUpon Submit "Reading/writing files" to Google