Go to Post In theory, this should work... Oops. - Eldarion [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 03-02-2015, 18:42
2B || !2B's Avatar
2B || !2B 2B || !2B is offline
/* No Comment */
FRC #1559 (DevilTech)
Team Role: Programmer
 
Join Date: Apr 2013
Rookie Year: 2013
Location: New York
Posts: 19
2B || !2B is a jewel in the rough2B || !2B is a jewel in the rough2B || !2B is a jewel in the rough2B || !2B is a jewel in the rough
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!
__________________
There are no brakes on the software train
Reply With Quote
  #2   Spotlight this post!  
Unread 03-02-2015, 18:44
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
Re: Text files on the roborio?

I was able to create files by specifying a absolute path, i.e.:
Code:
/home/lvuser/Output.txt
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
Reply With Quote
  #3   Spotlight this post!  
Unread 03-02-2015, 18:47
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,561
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
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
Reply With Quote
  #4   Spotlight this post!  
Unread 03-02-2015, 18:48
2B || !2B's Avatar
2B || !2B 2B || !2B is offline
/* No Comment */
FRC #1559 (DevilTech)
Team Role: Programmer
 
Join Date: Apr 2013
Rookie Year: 2013
Location: New York
Posts: 19
2B || !2B is a jewel in the rough2B || !2B is a jewel in the rough2B || !2B is a jewel in the rough2B || !2B is a jewel in the rough
Re: Text files on the roborio?

Thank you so much!
I guess ~/ only works in desktop linux.....
__________________
There are no brakes on the software train
Reply With Quote
  #5   Spotlight this post!  
Unread 03-02-2015, 19:13
kmodos kmodos is offline
Registered User
AKA: Alex
FRC #1126 (SparX)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: New York
Posts: 57
kmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to behold
Re: Text files on the roborio?

You also can output to a flashdrive using /U/ and /V/.
Reply With Quote
  #6   Spotlight this post!  
Unread 04-02-2015, 10:56
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,574
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Text files on the roborio?

Quote:
Originally Posted by 2B || !2B View Post
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");
.
.
Reply With Quote
  #7   Spotlight this post!  
Unread 26-02-2015, 15:43
shindigo shindigo is offline
Registered User
AKA: Mike Parker
FRC #0102
Team Role: Mentor
 
Join Date: Feb 2012
Rookie Year: 2009
Location: Somerville, NJ
Posts: 33
shindigo is an unknown quantity at this point
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
Reply With Quote
  #8   Spotlight this post!  
Unread 27-02-2015, 10:46
nickmcski nickmcski is offline
Registered User
AKA: Nicholas McCurry
FRC #1482 (Grandin Ghosts)
Team Role: Alumni
 
Join Date: Nov 2012
Rookie Year: 2012
Location: Canada
Posts: 107
nickmcski has a spectacular aura aboutnickmcski has a spectacular aura aboutnickmcski has a spectacular aura about
Re: Text files on the roborio?

Quote:
Originally Posted by shindigo View Post
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
Reply With Quote
  #9   Spotlight this post!  
Unread 27-02-2015, 16:21
shindigo shindigo is offline
Registered User
AKA: Mike Parker
FRC #0102
Team Role: Mentor
 
Join Date: Feb 2012
Rookie Year: 2009
Location: Somerville, NJ
Posts: 33
shindigo is an unknown quantity at this point
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
Reply With Quote
  #10   Spotlight this post!  
Unread 04-03-2015, 18:48
shindigo shindigo is offline
Registered User
AKA: Mike Parker
FRC #0102
Team Role: Mentor
 
Join Date: Feb 2012
Rookie Year: 2009
Location: Somerville, NJ
Posts: 33
shindigo is an unknown quantity at this point
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
Reply With Quote
  #11   Spotlight this post!  
Unread 06-03-2015, 21:28
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: Text files on the roborio?

Quote:
Originally Posted by shindigo View Post
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.
Reply With Quote
  #12   Spotlight this post!  
Unread 13-03-2015, 11:53
eddie12390's Avatar
eddie12390 eddie12390 is offline
Registered User
AKA: Eddie
FRC #3260 (SHARP)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Pittsburgh
Posts: 285
eddie12390 is a glorious beacon of lighteddie12390 is a glorious beacon of lighteddie12390 is a glorious beacon of lighteddie12390 is a glorious beacon of lighteddie12390 is a glorious beacon of light
Re: Text files on the roborio?

Quote:
Originally Posted by shindigo View Post
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.
__________________
Any post that I make expresses only my opinions. I do not represent the opinions of my team or of any entity affiliated with my team.

As a Mentor:
2016 - Engineering Inspiration at Greater Pittsburgh Regional

As a Driver:
2014 - Winner of Greater Pittsburgh Regional
Reply With Quote
  #13   Spotlight this post!  
Unread 14-03-2015, 00:25
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,574
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Text files on the roborio?

Quote:
Originally Posted by shindigo View Post
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.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #14   Spotlight this post!  
Unread 14-03-2015, 01:01
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: Text files on the roborio?

Quote:
Originally Posted by eddie12390 View Post
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.
Reply With Quote
  #15   Spotlight this post!  
Unread 13-04-2015, 19:15
ShortCircuit908's Avatar
ShortCircuit908 ShortCircuit908 is offline
King of Hacky Fixes
AKA: Caleb Milligan
FRC #4450 (Olympia Robotics Federation)
Team Role: Programmer
 
Join Date: Mar 2015
Rookie Year: 2014
Location: Olympia, WA
Posts: 7
ShortCircuit908 is an unknown quantity at this point
Re: Text files on the roborio?

Quote:
Originally Posted by GeeTwo View Post
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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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