|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools |
Rating:
|
Display Modes |
|
#1
|
||||
|
||||
|
Text files on the roborio?
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();
}
}
}
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! |
|
#2
|
|||
|
|||
|
Re: Text files on the roborio?
I was able to create files by specifying a absolute path, i.e.:
Code:
/home/lvuser/Output.txt |
|
#3
|
||||||
|
||||||
|
Re: Text files on the roborio?
We are writing files to /home/lvuser as described here: http://wpilib.screenstepslive.com/s/...15#FileStorage as well as to a usb drive at /media/sda1
|
|
#4
|
||||
|
||||
|
Re: Text files on the roborio?
Thank you so much!
I guess ~/ only works in desktop linux..... |
|
#5
|
|||
|
|||
|
Re: Text files on the roborio?
You also can output to a flashdrive using /U/ and /V/.
|
|
#6
|
|||||
|
|||||
|
Re: Text files on the roborio?
Quote:
Code:
.
.
Map<String, String> env = System.getenv();
.
.
f = new File(env.get("HOME") + "/Output.txt");
.
.
|
|
#7
|
|||
|
|||
|
Re: Text files on the roborio?
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 - mp |
|
#8
|
|||
|
|||
|
Re: Text files on the roborio?
Quote:
|
|
#9
|
|||
|
|||
|
Re: Text files on the roborio?
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. mp |
|
#10
|
|||
|
|||
|
Re: Text files on the roborio?
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. mp |
|
#11
|
|||
|
|||
|
Re: Text files on the roborio?
Note that it doesn't matter which USB port you plug it into. It matters what order you plug them in.
|
|
#12
|
||||
|
||||
|
Re: Text files on the roborio?
Quote:
|
|
#13
|
|||||
|
|||||
|
Re: Text files on the roborio?
Quote:
Quote:
They also included on the same page, probably more germane: Quote:
|
|
#14
|
|||
|
|||
|
Re: Text files on the roborio?
I have never rebooted after plugging in a thumb drive and it has always worked.
|
|
#15
|
||||
|
||||
|
Re: Text files on the roborio?
Quote:
Code:
File file = new File("Output.txt");
Code:
File file = new File("new_directory/Output.txt");
file.mkdirs();
file.createNewFile();
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|