Help me with java problem. (quickly!)
OK so we are having to do a very basic encoding/decoding program in our java class. Everything is working fine, I'm getting the right answers except they will not print out to a text file via PrintWriter (what our teacher told us to use). I am not very advanced in java though. Here is what I have for the method using PrintWriter. Please look and see if you can find anything wrong.
private void decode(){
PrintWriter output=null;
FileReader fr=null;
Scanner in=null;
try{
fr=new FileReader(inputFile);
in=new Scanner(fr);
output=new PrintWriter(outputFile);
}catch(IOException e){
System.out.println(e);
System.exit(1);
}
String finalWord;
while(in.hasNext()){
String codeword=in.next();
finalWord=toWord(codeword);
System.out.println(finalWord);
output.println(finalWord);
}
// output a message that the input file was decoded
System.out.println("Decoded file : " + inputFile);
// output how many errors were corrected
System.out.println("Errors corrected: " + numCorrected);
// output how many errors were detected
System.out.println("Errors detected: " + numDetected);
}
once again.. don't worry about anything else, the ONLY thing wrong with this program is that it won't print to the file (as prompted by the user.) it creates the text file, but with nothing in it.