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
|