October 13th, 2011, 10:46 AM
|
#5 (permalink)
|
|
Senior Member
Join Date: Jul 2010
Posts: 977
Device(s): Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Thanks: 52
Thanked 199 Times in 144 Posts
|
It doesn't matter how long it is. to read the first line of the above text, you would do this:
Code:
DataInputStream dis = new DataInputStream(new FileInputStream(new File(filename)));
String city = dis.readUTF();
int param1 = dis.readInt();
int param2 = dis.readInt();
It will automatically read in the proper number of bytes and convert it to the proper datatype.
EDIT: Actually, I made a mistake. DataInputStream reads and writes binary files. If you want to read a text file, you will want to just use a FileInputStream.
|
|
|
Last edited by jonbonazza; October 13th, 2011 at 10:49 AM.
|
|