Hi,
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:
Code:
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");
if(!f.exists()){
f.createNewFile();
}
fw = new FileWriter(f);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
bw = new BufferedWriter(fw);
}
public void teleopInit(){
try {
bw.write("Hellow, I'm a text file");
bw.close();
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
With this code I get the following error:
java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively(Nativ e Method)
at java.io.File.createNewFile(File.java:1012)
at org.usfirst.frc.team1559.robot.Robot.robotInit(Rob ot.java:32)
at edu.wpi.first.wpilibj.IterativeRobot.startCompetit ion(IterativeRobot.java:76)
at edu.wpi.first.wpilibj.RobotBase.main(RobotBase.jav a: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(Rob ot.java:39), edu.wpi.first.wpilibj.IterativeRobot.startCompetit ion(IterativeRobot.java:76), edu.wpi.first.wpilibj.RobotBase.main(RobotBase.jav a:234)]
WARNING: Robots don't quit!
---> The startCompetition() method (or methods called by it) should have handled the exception above.
Any help is appreciated!