Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 23rd, 2009, 10:35 PM
Registered User
 
Join Date: Aug 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Java Programming that read text file

helloo!

we have a project..the text file contains four number codes for the money in the bank, deposit, amount to withdraw and balance...the scenario are after I will run the code, it will compute the item and it will ask the number codes to display the content..help guyz!!

this is my code...

import java.io.*;



class ReadFile {

public static void main(String args[])throws IOException {



System.out.println("What is the name of the file to read from?");

String filename="File.txt";

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

filename = br.readLine();

System.out.println("Now reading from " + filename + "...");



FileInputStream fis = null;

try {



fis = new FileInputStream(filename);

} catch (FileNotFoundException ex) {



System.out.println("File not found.");



}



try {

char data;

int temp;

String word="";



do {

temp = fis.read();

data = (char) temp;

if (temp != -1) { //-1 is EOF

System.out.print(data);

/*if (data '') check the char if space or not

System.out.print(word);//find a function to add the char to the word

*/

if (word=="00001")

System.out.print("Money in the Bank");



if (word=="00002")

System.out.print("Amount to Withdraw");



if (word=="00003")

System.out.print("Your Balance");



}



} while (temp != -1);



} catch (IOException ex) {



System.out.println("Problem in reading the file.");



}

}

}
----------------------

this is my text file..

Bank Transaction



00001 $50,000

00002
00003
00004
 
Old August 23rd, 2009, 11:56 PM
jomet
Guest
 
Posts: n/a
Default

please include, wanted output too...
it will help, to understand your question.
 
Old August 25th, 2009, 01:38 AM
Registered User
 
Join Date: Aug 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the output should display the amount of withdraw or deposit and display balance basing from the money in the bank..it will just give an answer depends from the input given by the user.....

tnx for replying!!!





Similar Threads
Thread Thread Starter Forum Replies Last Post
read text file senthilreddy ASP.NET 1.0 and 1.1 Basics 1 December 19th, 2010 10:56 PM
Read Text file and convert to Binary file VB.net sjlsysprg1 Pro VB.NET 2002/2003 4 June 29th, 2007 06:53 AM
Read all rows from text file shai505 C# 5 April 28th, 2006 09:37 PM
Java Applet that can read XML DOM and display text sankar XML 3 February 16th, 2004 11:16 AM
Java Applet that can read an XML file sankar J2EE 1 December 25th, 2003 05:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.