• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading two text file using streamtokenizer

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic