Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Open text file (http://www.chiefdelphi.com/forums/showthread.php?t=102829)

Herbblood 14-02-2012 19:18

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:

Jeanne Boyarsky 14-02-2012 22:19

Re: Open text file
 
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

Re: Open text file
 
Quote:

Originally Posted by Jeanne Boyarsky (Post 1126874)
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

Re: Open text file
 
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...FRCKickoff.pdf

Herbblood 15-02-2012 18:12

Re: Open text file
 
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

Re: Open text file
 
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

Re: Open text file
 
This interface is implemented on our version of Java:
http://developers.sun.com/mobility/a...ileconnection/

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

Re: Open text file
 
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

Re: Open text file
 
this is how we have been able to open and read a text file which is terminated by a semi colon:

Code:

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



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

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