|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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. ![]() |
|
#2
|
|||
|
|||
|
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.
|
|
#3
|
|||
|
|||
|
Re: Open text file
YuP
|
|
#4
|
||||
|
||||
|
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 |
|
#5
|
||||
|
||||
|
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. Last edited by Herbblood : 15-02-2012 at 18:59. |
|
#6
|
||||
|
||||
|
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 |
|
#7
|
|||
|
|||
|
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 |
|
#8
|
||||
|
||||
|
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* Last edited by techkid86 : 17-02-2012 at 18:12. |
|
#9
|
|||
|
|||
|
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;
}
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|