473,396 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Reading text file with strings, double and boolean

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
2 2150
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
r035198x
13,262 8TB
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

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

Similar topics

3
by: muser | last post by:
With the following code I'm trying to read a text file (infile) and output inaccuracies to the error file (printerfile). The text file is written and stored on disk, while the printerfile has to be...
1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
8
by: Yeow | last post by:
hello, i was trying to use the fread function on SunOS and ran into some trouble. i made a simple test as follows: i'm trying to read in a binary file (generated from a fortran code) that...
4
by: Matthew Crema | last post by:
Hello, Say I have 1000 text files and each is a list of 32768 integers. I have written a C program to read this data into a large matrix. I am using fopen in combination with fscanf to read...
21
by: EdUarDo | last post by:
Hi all, I'm not a newbie with C, but I don't use it since more than 5 years... I'm trying to read a text file which has doubles in it: 1.0 1.1 1.2 1.3 1.4 2.0 2.1 2.2 2.3 2.4 I'm doing...
2
by: Clive Green | last post by:
Hello peeps, I am using PHP 5.2.2 together with MP3_Id (a PEAR module for reading and writing MP3 tags). I have been using PHP on the command line (Mac OS X Unix shell, to be precise), and am...
13
by: sugard | last post by:
Abstract Class, Inheritance, Polymorphism, File Handling, Exception Handing A program is to be devised for a university to work out whether or not, a student or a professor, is outstanding. The...
6
by: Sabiyur | last post by:
Hi All, The application I am doing requires hundreds of strings to be stored & retrieve those randomly. I think I can use microsoft resource ".rc" file to store the strings. I am not sure, how...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.