Problems Accessing Robot-Side File

Using the Connector paradigm to open a FileConnection and trying to read from it, I’m encountering errors. These seem to stem from the fact that a call to available() returns 0 bytes.

Does anyone have a solution? The file I am trying to open is on the root of the cRIO’s file system, so I could see file permissions being an issue (but I get no Exception to this effect, nor can I really justify this in my mind). I would try to relocate the file but have no idea what the default working directory of any code run on the robot is (nor do I really know how j2me handles things like this).

If you open the WPILib source code project in NetBeans and take a look at the Preferences class you can see some examples of file reading and writing. It reads the preferences file from the cRIO in the read() method from the constructor and writes to it when the save() method is called.

That should give you a pretty good idea of reading/writing text files.

Brad

Yes, I am doing it exactly like that. The available() method of the InputStream returns zero. The file is being uploaded to the root of the drive via FTP.

I might try using Preferences class, but I don’t like the idea of having to use NetworkTable to update the values.

Maybe that wasn’t so clear. I wasn’t thinking that you should necessarily use the Preference class except as an example of how to write code that does file I/O.

But if you did decide to use it as is, the network tables stuff in there is so that you can edit the preferences from the SmartDashboard. The network tables code isn’t used for reading and writing the preferences on the robot.

Brad