By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,806 Members | 1,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,806 IT Pros & Developers. It's quick & easy.

How do I read a Java file of floats into a float Variable?

P: 2
The Java file of floats are a line of floats. I want to read one float into a variable that I can send to processing code and process it, then get read he next float process it and read them all one at a time and process it.

Java file of floats:
Expand|Select|Wrap|Line Numbers
  1. 1319.88 1321.67 1312.22 1320.90 1321.39 1322.04 1322.35 1321.42 1312.34 1321.52 1320.25 1320.98 1320.85 1320.20 1320.63 1321.04 1321.35 1321.81 1322.13 1322.59 1322.16 1321.78 1322.18 1323.23 1322.46 1321.64 1321.31 1320.74 1321.19 1321.77 1322.39 1322.49 1323.21 1323.44 1323.22 1323.18 1323.00 1323.55 1323.65 1322.91 1323.29 1323.35 1322.22 1321.08 1320.79 1321.13 1319.84 1319.81
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.util.Scanner;
  3.  
  4. public class ScanXan2 {
  5.     public static float main(String[] args) throws IOException {
  6.         float CurrentQuote;
  7.  
  8.         try {
  9.  
  10.             CurrentQuote = new Scanner(new BufferedReader(new FileReader("data.java")));
  11.  
  12.             if (CurrentQuote.hasNext()) {
  13.                 System.out.println("CurrentQuote = " + CurrentQuote.next());
  14.                 return CurrentQuote;
  15.             }
  16.         } finally {
  17.             if (CurrentQuote == null) {
  18.                 CurrentQuote.close();
  19.             }
  20.         }
  21.     }
Apr 5 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.