Motorola Inc. | i88s J2ME Developers’ Guide |
readWrite();
break;
case 3: myDisplay.setCurrent(myOutput);
deleteFile();
break;
}
}else { myDisplay.setCurrent(myList);
}
}
private void setFileName() { myDisplay.setCurrent(tf1);
}
private void setData() { myDisplay.setCurrent(tf2);
}
private void readWrite() { int length = dataNum;
byte[] message = new byte[length]; message = stringNum.getBytes();
OutputStream os = null; InputStream is = null; try {
//open a file in the mode APPEND sc =
(StreamConnection)Connector.open("file://"+"fileURL"+";"+"APPEND"); //get OutputStream
os = sc.openOutputStream(); //get InputStream
is = sc.openInputStream(); //write the bytes to the file os.write(message); myOutput.append("write/append done");
//create an array to store available data from the file byte [ ] b1 = new byte[is.available()];
//read the bytes is.read(b1);
String readString = new String(b1); //printout the data in the phone screen myOutput.append(readString); myOutput.append("read finished"); //close all the opened streams
if (is != null) is.close(); if (os != null) os.close();
if (sc != null) sc.close();
} catch (Exception e) { System.out.println("Exception: " + e.getMessage()); try {
if (is != null) is.close(); if (os != null) os.close();
if (sc != null)
Version 1.0 - Page 26