Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Converting String to float

807589Jan 12 2009 — edited Jan 13 2009
ok - ive posted this issue on a few forums, to no avail
http://www.codeguru.com/forum/showthread.php?s=2285d18e7073ae78020b723c4091a679&t=468683
[nha khoa|http://www.sieuthi77.com/main/nhakhoa.html].com/showthread.php?t=1485

I need help again lol, im trying to code a load function, ive got it to read the files and put the values into strings, but i need to convert these to float type and nothing i try seems to work!

//Loads players saved statistics
void loadFile()
{

try {

FileReader file = new FileReader("winstat.dat");

BufferedReader buff = new BufferedReader(file);

String line = buff.readLine();
trans1 = line;

buff.close();

}
catch (IOException e) {

System.out.println("Error -- " + e.toString());

}

try {

FileReader file = new FileReader("loosestat.dat");

BufferedReader buff = new BufferedReader(file);

String line = buff.readLine();
trans2 = line;

buff.close();

}
catch (IOException e) {

System.out.println("Error -- " + e.toString());

}
try {

FileReader file = new FileReader("drawstat.dat");

BufferedReader buff = new BufferedReader(file);

String line = buff.readLine();
trans3 = line;

buff.close();

}
catch (IOException e) {

System.out.println("Error -- " + e.toString());

}
message.setText(trans1);
}


The files contain single float numbers, e.g.: 6.0

Thanks for any help!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 10 2009
Added on Jan 12 2009
3 comments
576 views