472,779 Members | 2,498 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 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 2119
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.