Text files on the roborio?


Does anyone know how to write text files to storage on the roborio with java?

If so, what directories do I have access to?

Here’s my code if it helps:

package org.usfirst.frc.team1559.robot;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import edu.wpi.first.wpilibj.IterativeRobot;

public class Robot extends IterativeRobot {
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
	File f;
	BufferedWriter bw;
	FileWriter fw;
    public void robotInit() {
    	try {
    		f = new File("~/Output.txt");
			fw = new FileWriter(f);
		} catch (IOException e) {
			// TODO Auto-generated catch block
    	bw = new BufferedWriter(fw);

    public void teleopInit(){
    	try {
			bw.write("Hellow, I'm a text file");
		} catch (IOException e) {
			// TODO Auto-generated catch block

With this code I get the following error:
java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:1012)
at org.usfirst.frc.team1559.robot.Robot.robotInit(Robot.java:32)
at edu.wpi.first.wpilibj.IterativeRobot.startCompetition(IterativeRobot.java:76)
at edu.wpi.first.wpilibj.RobotBase.main(RobotBase.java:234)
ERROR Unhandled exception: java.lang.NullPointerException at [java.io.Writer.<init>(Writer.java:88), java.io.BufferedWriter.<init>(BufferedWriter.java:101), java.io.BufferedWriter.<init>(BufferedWriter.java:88), org.usfirst.frc.team1559.robot.Robot.robotInit(Robot.java:39), edu.wpi.first.wpilibj.IterativeRobot.startCompetition(IterativeRobot.java:76), edu.wpi.first.wpilibj.RobotBase.main(RobotBase.java:234)]
WARNING: Robots don’t quit!
—> The startCompetition() method (or methods called by it) should have handled the exception above.

Any help is appreciated!

I was able to create files by specifying a absolute path, i.e.:


We are writing files to /home/lvuser as described here: http://wpilib.screenstepslive.com/s/4485/m/13810/l/292213-c-java-porting-guide-2014-to-2015#FileStorage as well as to a usb drive at /media/sda1

Thank you so much!
I guess ~/ only works in desktop linux…

You also can output to a flashdrive using /U/ and /V/.

The ~ is normally interpreted by the shell, not the kernel. I believe that java is attempting to open the file directly through an fopen() or equivalent call. I believe that you can get the value of the HOME environment variable and use it in place of the ~ to avoid hardcoding paths.

        Map<String, String> env = System.getenv();
        f = new File(env.get("HOME") + "/Output.txt");

Hi All -
I have looked around the links on this post for more information about using a USB stick, but can’t find much.

I see that I can reference /U/ and /V/ (presumably for the two USB ports).

When I plug a Kingston NTFS-formatted USB stick and connect via FTP (Filezilla) I can see the KINGSTON device, but not the folders. I assume this is because the stick is formatted NTFS.

If I use a FAT-formatted USB stick, will I see it as /U or /V depending on the port it is plugged into? Any other fine points about getting this to work for data logging?

tia -


If you look above at what Joe Ross said I think that will answer your question. He says the USB drives will be mounted to /media/sda1

Sorry forgot to mention that I did look for /media/sda1, and I do not see the device listed that way. Neither do I see it listed as U or V.

I have since formatted my device as FAT and tried again with no luck. It is a 64Gb stick - any chance there is a size limit?

As an alternative I could use the internal storage. Read in the specs for the Roborio that the internal storage capacity is 256 MB. Can anyone tell what the approx remaining capacity is after loading JRE and robot program? Filezilla is not help me figure that out.


Happy to report that I finally got this working using another smaller, FAT formatted USB stick.

Placed in the bottom USB port (the one closest the logo) this appears as: /u, /U and /media/sda1.

So I guess we should avoid NTFS and very large capacity sticks.


Note that it doesn’t matter which USB port you plug it into. It matters what order you plug them in.

This is probably a stupid question, but did you restart the robot after plugging in the flash drive? We’ve had to do this every time that we used one.

FAT was traditionally limited to 4Gb. It seems to have been extended a bit. However, a recent search turned up:

You cannot decrease the cluster size on a volume using the FAT32 file system so that the FAT ends up larger than 16 MB less 64 KB in size.

It sounds like Micros*** is utterly muddying the waters yet again; this is worse than traditional by several orders of magnitude.
They also included on the same page, probably more germane:

You cannot format a volume larger than 32 GB in size using the FAT32 file system in Windows 2000. The Windows 2000 FastFAT driver can mount and support volumes larger than 32 GB that use the FAT32 file system (subject to the other limits), but you cannot create one using the Format tool. This behavior is by design. If you need to create a volume larger than 32 GB, use the NTFS file system instead.

I have never rebooted after plugging in a thumb drive and it has always worked.

Another option is simply defining a non-absolute path, which would make the file relative to the working directory (where the jar file is located).

File file = new File("Output.txt");

Other than that, referring to solving “File or directory not found,” you also have to create the directory that the desired file resides in, in addition to the actual file.

File file = new File("new_directory/Output.txt");

This would ensure that the directory “new_directory” is created before “Output.txt” is created.