If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

A Filereader and Writer, with a little work

Greetings all,
The aim of this class is to take a text file, and identify each unique word. I want to save the words into an array, and use each words' place in the array as an I.D. If the word is new, place it at the end of the array and print its id. If the word has been encountered before, I just want to print its I.D. The printed I.D's will make up a new text file, in QDimacs format.
So far I have a BufferedReader and BufferedWriter, Ive tried reading in a text document, and I'm getting a new text document in the required format, but its blank. Any idea's?

try {
// attempt to open the words file, and the new qdimacs file
BufferedReader br = new BufferedReader(new FileReader(file));
BufferedWriter wr = new BufferedWriter(new FileWriter(fileName));

String word = br.readLine();
String[] words = null;
int i;
int x;

// loop and read a line from the file as long as we dont
// get null

while (word != null) {
words = word.split(" ");
// compare the words to those in the arrayList

for (i = 1; i < wordList.size(); i++) {
String s = wordList.get(i);

for (x = 0; x < words.length; x++) {
String w = words[x].toString();

if ((s.equals(w)) == true) {
// if the word has been seen before, print the words place in the array
wr.write(i);
wr.newLine();
}
// If the word hasn't been seen before, place it on the end of the
// array and print its place.
else
wordList.add(word);
wr.write(wordList.size());
}
}
br.close();
wr.close();
}

Does your code work as expected if you use the "append" signal in creating your FileWriter object? [sounds like you are experiencing the only content of your file is a new line, which is why your file is blank]