Results 1 to 2 of 2

Thread: Help with printing to file..

  1. #1

    Thread Starter
    Hyperactive Member nickwrs's Avatar
    Join Date
    Jan 2000
    Location
    Atlanta, Ga
    Posts
    398

    Unhappy Help with printing to file..

    Okay, below is my code, it is supposed to (btw this is for a class project in case you are wondering why any one would want to do this) okay, it is supposed to take in a file and replace all the letters of one type with another.

    So far as I can tell it reads in the file well, and then it parses it
    into a vector with the appropriate text strings

    But when I try to write out to a file, then it simply makes the file name but writes nothing to it.


    If any one can help I would appreciate it.

    public static void fileReplaceCopy(String readFrom, String writeTo,
    char toReplace, char replaceWith){

    try{
    Vector v = new Vector();
    FileReader myFile;
    BufferedReader inputFile = null;
    String line;
    PrintWriter out =
    new PrintWriter(new BufferedWriter( new FileWriter(writeTo)));


    myFile = new FileReader(readFrom);
    inputFile = new BufferedReader(myFile);

    while( (line = inputFile.readLine()) != null){
    v.addElement(line.replace(toReplace,replaceWith));
    }

    int i = 0;
    while (v.elementAt(i) != null){
    System.out.println(v.elementAt(i));
    out.println (v.elementAt(i));
    i ++;
    }

    out.close();

    myFile.close();
    }

    catch (Exception e){}

  2. #2

    Thread Starter
    Hyperactive Member nickwrs's Avatar
    Join Date
    Jan 2000
    Location
    Atlanta, Ga
    Posts
    398
    Never mind, I fixed it. I wasn't handling errors and when I did I realized I had an outof Bounds exception.

    So it never closed the file.

    lol
    Sorry to bother you all.

Posting Permissions

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



Click Here to Expand Forum to Full Width