Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Reading a text file

807597Jan 13 2005 — edited Jan 14 2005
Hi,
I'm currently making a bank account program that allows an account to be created and then each line written to a text file where it is stored until it needs to be read.
I have had no problems writing the file but i'm having a little trouble reading it.
All the info for each account is on a seperate line and what i'd like to do is read just one line of the file (a number) and be able to do a calculation with it before putting the new value back into the file.

Here is the code i have written so far but it reads all the lines of the file and i'm not sure how i can use one line to do a calculation. Any help would be very much appreciated.


import java.io.*;
import javax.swing.*;

public class Deposit
{
public static void main (String args[])
{
try
{
FileReader ifile = new FileReader("AccountOne.txt");
BufferedReader bufStream = new BufferedReader(ifile);
boolean eof = false;
//while(!eof)
//{
String line = bufStream.readLine();
if(line == null)
eof = true;
else
System.out.println(line);
//}
bufStream.close();
}
catch(IOException e)
{
System.out.println("Error - " + e.toString());
}


}//main()
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 11 2005
Added on Jan 13 2005
3 comments
133 views