• Post Reply Bookmark Topic Watch Topic
  • New Topic

reading floats form text file

 
Patrick ODonnell
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a text file as follows:
-0.891
0.893
1.022
.
.
i.e. a list of numbers.
I want to be able to read in each line and store it in a float[] array, so i can perform some math operations on it. how do I do this.
Thanks,
Patrick.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BufferedReader.readLine() is the best way to read lines of text. Open a FileReader first, then open a BufferedReader using your FileReader.
Double.parseDouble() is a way to convert String to double value (or Float.parseFloat(), as required). You might need to String.trim() first, to remove any whitespace.
[This message has been edited by Peter Chase (edited November 29, 2001).]
 
Patrick ODonnell
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Peter, that was very helpful
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!