Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading two text file using streamtokenizer

 
Pauline Pauline
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem you have mentioned is definetly not with your code.
Can you tell what command you are using to compile and what exactly is the error you are getting.
Make sure your java file has an extension .java and you specify this in calling javac
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic