Hi,
I am having problems counting the number of words in a text file that i created (it has 130) and printing that finding (number) into another text file (output)....Any help is welcomed. I have this, but it doesn't print anything out yet...am stuck.
import java.io.*;
public class FileIO{
public static void main(String[] args)throws IOException {
}
public static int WordCount(String line) throws IOException {
FileReader inputStream = null;
FileWriter outputStream = null;
try {
inputStream = new FileReader("G:\\Java 1302\\project\\FILEIO\\src\\input.txt");
outputStream = new FileWriter("G:\\Java 1302\\project\\FILEIO\\src\\output.txt");
int numWords = 0;
int index = 0;
boolean prevWhiteSpace = true;
while(index < line.length()){
char c = line.charAt(index++);
boolean currWhiteSpace = Character.isWhitespace(c);
if(prevWhiteSpace && !currWhiteSpace){
numWords++;
}
prevWhiteSpace = currWhiteSpace;
}
return numWords;
} finally {
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
}
}
}