Converting String to float

  • lhpnhi1980
  • Newbie
  • Newbie
  • lhpnhi1980
  • Posts: 13

Post 3+ Months Ago

I'm 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!

Code: [ Select ]
//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);
}
  1. //Loads players saved statistics
  2. void loadFile()
  3. {
  4. try {
  5. FileReader file = new FileReader("winstat.dat");
  6. BufferedReader buff = new BufferedReader(file);
  7. String line = buff.readLine();
  8. trans1 = line;
  9. buff.close();
  10. }
  11. catch (IOException e) {
  12. System.out.println("Error -- " + e.toString());
  13. }
  14. try {
  15. FileReader file = new FileReader("loosestat.dat");
  16. BufferedReader buff = new BufferedReader(file);
  17. String line = buff.readLine();
  18. trans2 = line;
  19. buff.close();
  20. }
  21. catch (IOException e) {
  22. System.out.println("Error -- " + e.toString());
  23. }
  24. try {
  25. FileReader file = new FileReader("drawstat.dat");
  26. BufferedReader buff = new BufferedReader(file);
  27. String line = buff.readLine();
  28. trans3 = line;
  29. buff.close();
  30. }
  31. catch (IOException e) {
  32. System.out.println("Error -- " + e.toString());
  33. }
  34. message.setText(trans1);
  35. }


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

Thanks for any help!

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 69 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.