Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Text files on the roborio? (http://www.chiefdelphi.com/forums/showthread.php?t=133932)

2B || !2B 03-02-2015 18:42

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();
                }
           
    }
}

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!

Ben Wolsieffer 03-02-2015 18:44

Re: Text files on the roborio?
 
I was able to create files by specifying a absolute path, i.e.:
Code:

/home/lvuser/Output.txt

Joe Ross 03-02-2015 18:47

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

2B || !2B 03-02-2015 18:48

Re: Text files on the roborio?
 
Thank you so much!
I guess ~/ only works in desktop linux.....

kmodos 03-02-2015 19:13

Re: Text files on the roborio?
 
You also can output to a flashdrive using /U/ and /V/.

GeeTwo 04-02-2015 10:56

Re: Text files on the roborio?
 
Quote:

Originally Posted by 2B || !2B (Post 1437883)
Thank you so much!
I guess ~/ only works in desktop linux.....

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.

Code:

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


shindigo 26-02-2015 15:43

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

nickmcski 27-02-2015 10:46

Re: Text files on the roborio?
 
Quote:

Originally Posted by shindigo (Post 1450272)
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

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

shindigo 27-02-2015 16:21

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

shindigo 04-03-2015 18:48

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

jhersh 06-03-2015 21:28

Re: Text files on the roborio?
 
Quote:

Originally Posted by shindigo (Post 1453649)
Placed in the bottom USB port (the one closest the logo) this appears as: /u, /U and /media/sda1.

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

eddie12390 13-03-2015 11:53

Re: Text files on the roborio?
 
Quote:

Originally Posted by shindigo (Post 1450806)
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

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.

GeeTwo 14-03-2015 00:25

Re: Text files on the roborio?
 
Quote:

Originally Posted by shindigo (Post 1450806)
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?

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

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:
Quote:

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.

jhersh 14-03-2015 01:01

Re: Text files on the roborio?
 
Quote:

Originally Posted by eddie12390 (Post 1457274)
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.

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

ShortCircuit908 13-04-2015 19:15

Re: Text files on the roborio?
 
Quote:

Originally Posted by GeeTwo (Post 1438168)
Code:

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


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).
Code:

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.

Code:

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

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


All times are GMT -5. The time now is 10:34.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi