Log in

View Full Version : File Handling


Patrick Chiang
18-02-2010, 21:07
How would I read/write from a file in Java? It seems that FRC has omitted the Scanner and the FileOutputStream classes, the only ways I know how to do file io.

Thanks in advance

rrossbach
19-02-2010, 20:47
Look at the javadocs for the following classes:

com.sun.squawk.microedition.io.FileConnection
javax.microedition.io.Connector
java.io.DataOutputStream
java.io.DataInputStream

For example, to create an output file on the cRIO:

DataOutputStream theFile;
FileConnection fc;

try {
fc = (FileConnection)Connector.open("file:///output.txt", Connector.WRITE);
fc.create();
theFile = fc.openDataOutputStream();
} catch (Exception e) {
...
}

You can then use the writeXXX() methods in DataOutputStream to write to the file. Be sure to flush() also.

- Ron
Team #2607 controls mentor