Log in

View Full Version : file i/o in java


amk
06-04-2010, 14:09
Does anyone have example code for how to open and write to a text file on the cRIO? We would like to write out information while the robot for debugging purposes, then ftp the file to a laptop for viewing. Any help is appreciated.

Robototes2412
06-04-2010, 17:49
if i remember right, they removed that feature from java, i suggest writing a class in c++ then use JNA to call it

rrossbach
06-04-2010, 20:37
Does anyone have example code for how to open and write to a text file on the cRIO? We would like to write out information while the robot for debugging purposes, then ftp the file to a laptop for viewing. Any help is appreciated.

Take a look at my post here (http://www.chiefdelphi.com/forums/showpost.php?p=924217&postcount=2) for an example.

- Ron
Team #2607 controls mentor

derekwhite
07-04-2010, 23:20
I'll second Ron's approach.

As an FYI, once you have an OutputStream to the file, you can wrap it with a PrintStream and use the typical print methods on the file.



PrintStream out;
DataOutputStream theFile;
FileConnection fc;

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

spartango
08-04-2010, 02:49
See
http://code.google.com/p/grtframework/source/browse/trunk/CurrentBot/src/com/grt192/utils/GRTFileIO.java

You can use that file verbatim or copy it and use its innards in your code.

Robototes2412
08-04-2010, 13:20
THanks, is there anyway to append to a file?