Open text file

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:

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

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

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():wink: 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.

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

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

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*=dataStream.readChar();
}
System.out.println(new String©);

any suggestions?

found it… nvm… face palm*

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