Results 1 to 3 of 3
  1. #1
    porchrat is offline Senior Member
    Join Date
    Mar 2009
    Rep Power

    Default [SOLVED] Writing to a file

    I am trying to write to a file and I don't really know what I'm doing wrong here. If someone could point me in the right direction that would be great.

    Java Code:
    BufferedWriter writer = new BufferedWriter (new FileWriter(foo));
    for (int count = 0; count <= (listArray.length - 1); count++)
    It is supposed to write each field of the array to the File foo, one at a time. Each needs to be on its own line (perhaps BufferedWriter.write() moves the cursor to the next line, but I doubt it, hence the "\n"). Can anyone explain why this isn't working?

    It is really starting to annoy me because I'm pretty sure I'm doing something stupid here and I don't know what it is.
    Last edited by porchrat; 04-29-2009 at 06:18 PM.

  2. #2
    porchrat is offline Senior Member
    Join Date
    Mar 2009
    Rep Power


    Nevermind I figured it out.

    It was something stupid after all. Above that code mentioned in the previous post I was reading a file into that array using a BufferedReader wrapped around a FileReader and I had forgotten to close that Reader.

    Thanks anyway everyone :) will mark as solved

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Rep Power

    Default flush & close

    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Reading/Writing to file
    By Doctor Cactus in forum New To Java
    Replies: 2
    Last Post: 10-28-2008, 02:05 PM
  2. Writing to DAT or TXT file
    By hunterbdb in forum Advanced Java
    Replies: 7
    Last Post: 10-12-2008, 02:50 PM
  3. Replies: 9
    Last Post: 07-10-2008, 04:52 PM
  4. Writing to a file (at the end)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:22 AM
  5. writing to a file
    By bugger in forum New To Java
    Replies: 1
    Last Post: 11-11-2007, 02:49 AM

Posting Permissions

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