• Lucid Dreaming - Dream Views




    Results 1 to 1 of 1
    1. #1
      Amateur Psychonaut pyroguy305's Avatar
      Join Date
      Jan 2007
      LD Count
      1.5
      Gender
      Location
      The horribly designed town of Cary.
      Posts
      238
      Likes
      2
      DJ Entries
      3

      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.
      Last edited by pyroguy305; 03-23-2009 at 06:01 AM. Reason: wrong code posted.

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •