F
farah
Hi, ive written some code to feed a text file into my program, as shown
below, it currently displays the first line of the text file (this is
not needed, it was just a check to make sure the code worked).
Im not sure how i would go about storing the text file (a list of
words) in a hashset so that i can later compare two text files....im
thinking i may need to use a streamTokenizer? can anyone start me off
with some code? or just give me some pointers please??
import java.io.*;
public class FileIn {
// assigns BufferedReader an instance name to be used in the code
BufferedReader in;
public FileIn() {
try {
// make sure there is a text file in the java directory where the java
// code is saved
in = new BufferedReader(new FileReader("\\C:\\Program
Files\\java.txt\\"));
String line = in.readLine();
System.out.println(line);
// i think this code only allows for the first line to be read
// because it closes after one line is read and printed
in.close();
// if any error occured during the try statement the system will
display
// the error that it encountered
} catch(IOException ioe) {
System.out.println(ioe.toString());
}
}
public static void main(String args[]) {
//this gets executed when the java file is run
// this then (starting from the top) does what u tell it
FileIn newFile = new FileIn();
}
}
below, it currently displays the first line of the text file (this is
not needed, it was just a check to make sure the code worked).
Im not sure how i would go about storing the text file (a list of
words) in a hashset so that i can later compare two text files....im
thinking i may need to use a streamTokenizer? can anyone start me off
with some code? or just give me some pointers please??
import java.io.*;
public class FileIn {
// assigns BufferedReader an instance name to be used in the code
BufferedReader in;
public FileIn() {
try {
// make sure there is a text file in the java directory where the java
// code is saved
in = new BufferedReader(new FileReader("\\C:\\Program
Files\\java.txt\\"));
String line = in.readLine();
System.out.println(line);
// i think this code only allows for the first line to be read
// because it closes after one line is read and printed
in.close();
// if any error occured during the try statement the system will
display
// the error that it encountered
} catch(IOException ioe) {
System.out.println(ioe.toString());
}
}
public static void main(String args[]) {
//this gets executed when the java file is run
// this then (starting from the top) does what u tell it
FileIn newFile = new FileIn();
}
}