Log in

View Full Version : Open text file


Herbblood
14-02-2012, 19:18
One of my teammates is trying to open a text file(.txt) on the robot. We not have found the correct methods.
Please respond! Thank you.
:confused:

Jeanne Boyarsky
14-02-2012, 22:19
There is a class called InputStreamReader available in Java ME (robot version) that can read from a file. If you search for InputStreamReader on the internet, you will find some examples of how to use it.

Chiller
14-02-2012, 23:31
There is a class called InputStreamReader available in Java ME (robot version) that can read from a file. If you search for InputStreamReader on the internet, you will find some examples of how to use it.

YuP

TravSatEE
15-02-2012, 00:06
The best overview of the file read/write code I have seen is available in [1] around slide 7 with example code.

[1] http://www.usfirst.org/uploadedFiles/Robotics_Programs/FIRST_Place/Workshops_and_Conferences/2010_Assets/JavaForFRCKickoff.pdf

Herbblood
15-02-2012, 18:12
Okay i got the FileConnection file = (FileConnection) it says unreported exception java.io.IOException must be caught or declared to be thrown,and when i do the try catch if still says that.
As well as i can't(when it is put as FileConnectionfile = new File Connection();) is says that the sunsquack is abstract and cannot be instantiated.
Any ideas as what to do please?
If anyone has actual code to open a (.txt) file on netbeans it would be deeply apprectiated!
Thank you.

techkid86
15-02-2012, 20:15
we've looked at that, but we are still having issues. we want to open a text file that has a large number of double numbers seperated by newlines. the totoral posted are more directed at outputting(which is nice though) any other totorals or sites?

ty all in advance

ItzWarty
16-02-2012, 16:57
This interface is implemented on our version of Java:
http://developers.sun.com/mobility/apis/ttips/fileconnection/

I'd assume that they wouldn't reinvent the wheel (or in this case, the API)

I've used that API for TCP Sockets

techkid86
17-02-2012, 16:15
we has this as code, but it only reads every other character.
ex.
in text file: 1234.5678
reads out: 2457

i have checked the character encoding, and it seems to be in ASCII. but, the read char is in Unicode. so i outputed the raw bytes, and converted it into ASCII, and the output just was the ASCII reprisentation.

DataInputStream dataStream=new DataInputStream("file:///FTPtest.txt");
char[] c=new char[9];
for (int i=0;i<9;i++)
{
c[i]=dataStream.readChar();
}
System.out.println(new String(c));


any suggestions?


found it.... nvm.... *face palm*

Secretspy97
17-02-2012, 20:44
this is how we have been able to open and read a text file which is terminated by a semi colon:


private final String PATH = "file:///Sparx/mytxt.txt";
private final char ESC_CHAR = ';';

try
{
FileConnection read = (FileConnection) Connector.open(PATH, Connector.READ);
fileRead = read.openDataInputStream();

String theString = "";
while(true)
{
byte ch = fileRead.readByte();
if(ch == ESC_CHAR)
{
break;
}
theString += (char) ch;
}