Hi all,
i have written a program to read a text file using streamtokenizer but there's some program when i compile and it says no source file but i have already put the text file into the folder together with the
java program .Can anyone help me ?
Here's the program :
import java.io.*;
import java.util.*;
class TokenTest {
public static void main (
String[] args) {
TokenTest tt = new TokenTest();
tt.dbTest();
}
void dbTest() {
DataInputStream dis = null;
String dbRecord = null;
String dbBase =null;
try {
File f = new File("studentScore1.txt");
File a = new File("studentScore2.txt");
FileInputStream fis = new FileInputStream(f);
FileInputStream fin = new FileInputStream(a);
BufferedInputStream bis = new BufferedInputStream(fis);
BufferedInputStream bia = new BufferedInputStream(fin);
dis = new DataInputStream(bis);
eis = new DataInputStream(bia);
// read the first record of the database
while ( (dbRecord = dis.readLine()) != null) {
StringTokenizer st = new StringTokenizer(dbRecord, "");
String studentID = st.nextToken();
String score = st.nextToken();
System.out.println("StudentIDScore" );
System.out.println(studentID+score);
}
while ( (dbBase= eis.readLine()) != null) {
StringTokenizer st = new StringTokenizer(dbBase, "");
String studentID = st.nextToken();
String score = st.nextToken();
System.out.println("StudentIDScore" );
System.out.println(studentID+score);
}
} catch (IOException e) {
// catch io errors from FileInputStream or readLine()
System.out.println("Uh oh, got an IOException error: " + e.getMessage());
} finally {
// if the file opened okay, make sure we close it
if (dis != null) {
try {
dis.close();
} catch (IOException e) {
System.out.println("IOException error trying to close the file: " +
e.getMessage());
}
} // end if
} // end finally
} // end dbTest
} // end class