Go to Post Adaptability is the key folks. Your job will not be the same 10 years from now (when I retire), or 20 years or 30 years from now. The tools and systems you use will change, and you must be able to adapt along with them. - Bill Moore [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

 
 
 
Thread Tools Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 03:03.

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