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

Reading text file with strings, double and boolean

P: 8
The script works but I'm having a problem reading double and boolean

Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.io.*;
  3. import java.util.StringTokenizer;
  4. import javax.swing.JOptionPane;
  5.  
  6. public class FileAddress
  7. {
  8.   public static void main(String [] args)
  9.   { 
  10.     String aRecord; //for record
  11.     String accountNumber;
  12.     String customerName;
  13.     String customerPhone;
  14.     double customerBalance; //account balance
  15.     boolean accountStatus;  //true if account is active, false if not
  16.  
  17.     StringTokenizer strings;
  18.  
  19.     try
  20.     {
  21.         FileReader inStream = new FileReader("account.txt");
  22.         BufferedReader ins = new BufferedReader(inStream);
  23.  
  24.       while ((aRecord=ins.readLine())!= null)
  25.       {
  26.         strings = new StringTokenizer(aRecord,"?"); //toekenizer
  27.         if (strings.countTokens() == 5) {
  28.           accountNumber = strings.nextToken();
  29.           customerName = strings.nextToken();
  30.           customerPhone = strings.nextToken();
  31.           customerBalance = strings.nextToken(); //ERROR
  32.           customerStatus = strings.nextToken(); //ERROR
  33.           JOptionPane.showMessageDialog(null,accountNumber); 
  34.           JOptionPane.showMessageDialog(null,customerName+"  "+customerPhone+"  "+customerBalance);
  35.  
  36.         }
  37.       }
  38.       ins.close();
  39.     }
  40.      catch(IOException e)
  41.      {
  42.        e.printStackTrace();
  43.      }
  44.   }
  45. }    
Jan 29 '08 #1
Share this Question
Share on Google+
2 Replies


P: 8
Ok this is what I did to fix the double variable

//Double customerBalance;

Expand|Select|Wrap|Line Numbers
  1. customerBalance = strings.nextToken(); //ERROR
I changed it to

Expand|Select|Wrap|Line Numbers
  1. customerBalance  = Double.parseDouble(strings.nextToken());
Now, how can I resolve string to boolean? I get an error with

Expand|Select|Wrap|Line Numbers
  1. boolean(strings.nextToken()); //ERROR
Jan 30 '08 #2

10K+
P: 13,264
Ok this is what I did to fix the double variable

//Double customerBalance;

Expand|Select|Wrap|Line Numbers
  1. customerBalance = strings.nextToken(); //ERROR
I changed it to

Expand|Select|Wrap|Line Numbers
  1. customerBalance  = Double.parseDouble(strings.nextToken());
Now, how can I resolve string to boolean? I get an error with

Expand|Select|Wrap|Line Numbers
  1. boolean(strings.nextToken()); //ERROR
In a similar manner ...
Jan 30 '08 #3

Post your reply

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