BufferedWriter cannot append to file ....just overwrites

Hello all,
I have a java file that is an somewhat of a Event Handler.
I have a method inside that is called many times while program runs.  public void writeToFile(String string)
      try
            BufferedWriter writer = new BufferedWriter(new FileWriter("foo.txt"));
            writer.append(string);
           // writer.write(string); tried this also.
            writer.flush();
            writer.close();
      catch(IOException io)
                io.printStackTrace();
  }Problem is that I only get one line written to foo.txt, and each time I run the program it overwrites that one line with another value.
Expected results are at least 4 lines would be written in foo.txt each time I run program.
Any ideas?
TIA!

I dont suppose that you know if it is possible to
append to the top (beginning)of the file?That would be inserting. To do that, you could store the whole file, then rewrite the file, putting the old data after your new data.
Or you could create a new file, write the new data to it, then read the old file and write the data there to the new file. After that, delete the old file and rename the new file.

Similar Messages

  • Cannot play hdv file, just sound!

    I just bought a new iMac for the editing of my short film, but quicktime can't play the files. I only hear sound. Final Cut express can't read it either. My friend transfer the hdv files for me in my external hard drive, he says he could play the videos on his mac. I really don't know what to do, I nead to see wat i shot AND edit it.
    Please someone help me

    Yes, iMovie 8 can handle this:
    http://docs.info.apple.com/article.html?path=iMovie/7.0/en/15202.html
    Somebody else asked the same question a year go in this thread:
    http://discussions.apple.com/thread.jspa?threadID=1126473
    Have a look at Karsten's first reply.

  • ERROR: Final Cut cannot read the file just captured.

    I get this message whenever I attempt to capture via DV NTSC using Capture Now.
    I have used basic A/V, capture settings.
    Please advise.

    Perhaps you are capturing to a drive not formatted as Mac OS Extended.
    x

  • I have downloaded the two files needed for the upgrade of Adobe Photoshop Elements 8 to version 12 but I cannot open them to make them run and install. What am I supposed to do. One is a very large .7z file just over 1gb in size.

    How do I open  up a .7z file just over 1gb in size? I have just downloaded this as an upgrade from Adobe Photoshop Elements 8 to version 12. I cannot see any sign of the Akamai program on my computer that is supposed to open and install the two files that I downloaded.

    Thanks Hans
    I don’t mind mountain climbing but anything serious to do with a computer scares me silly.
    I installed the 64 bit version of 7zip and once I figured out how to tell the computer to use the right application within that to open the 7zip file, the big file opened and I was able to apply the .exe file to get things going and installed. In the end the default location the installation chose was program files x86 which I think is the 32 bit folder but it all seems to be ok now.
    Many thanks again for your response.
    Cheers
    Peter

  • I have updated to Keynote 6.1, but I still have 5.3 and I cannot open the file I just created in 6.1.

    I have updated to Keynote 6.1, my App Store says I did it 2/1/14, I just created a new slideshow in 6.1 tonight, saved it all the way through while creating it, and when finished, saved it one more time, and closed the file. I treid to open it again, but I get an error message stating I need a newer version of Keynote to open the presentation. I check the "About Keynote", and apparently I still have 5.3 and I cannot open the file I just created in 6.1. I try changing the file to open with 5.3, but it won't do that either! The App Store won't let me re-download it. How do I get 6.1 back??? I need to reopen the file I just created.

    I am finding that when I launch keynote from the Docking Station and it opens Keynote 5.3, so I command Q and close it. I then go to Finder, go to the Keynote slideshow I created in 6.1 and now cannot open, and CAN open the slideshow from Finder, which it actually open the file in Keynote 6.1.
    I emptied my Trash.
    What the heck is up with this???? And how do I fix it??

  • Just bought Canon 40d - Use CS2 - Cannot read Raw files in Bridge

    Heading says it all really. Just purchased new Canon 40D Body and have been using CS2 on Mac OS 10.4 for over two years. Cannot read RAW files in Photoshop Bridge which is what I have used consistently with 20D files up to now. Quick search on Google brought up fact that Adobe had not up upgraded Bridge to read new 40D files but that was 2 years ago. Am now looking for plug-in! Can anyone help or am I now forced to upgrade my CS2 or move away to Aperture or Lightroom? Any help gratefully received. Rob

    The 40d is not supported by any version of Camera Raw that can run in CS2.  You need at least CS3 and ACR 4.2 or greater.
    Dowload the free, stand-alone Adobe DNG Converter 5.3 and convert the raw files from your 40d to raw DNGs first, then you can open the DNG files in ACR 3.7 hosted by CS2.

  • I just tried to update Firefox to version 9.0.1. It got to 13% extracting, then I got an error message, Cannot Open Output File. Can you please help me?

    I just tried to update Firefox to version 9.0.1. It got to 13% extracting, then I got the error message, Cannot Open Output File.

    The file could be downloaded incorrectly. Could you redownload it again from [http://getfirefox.com http://getfirefox.com]?

  • Cannot create a file when that file already exists, but should overwrite

    Hi,
    I need the same file name which is at Sender side and when it reaches to Receiver directory without timestamp.
    for eg., Sender side : Yeswanth.txt
    and also receiver side   :  Yeswanth.txt
    but, here it should overwrite the existing file (because, the sender side file name is always constant) at receiver directory when the job schedules for each time.
    Processing parameters i has given on Receiver side:
    File Construction Mode  :  Create
    put file  : Use Temporary File
    and I enabled the Adapter Specific Message Attributes at Sender side and Receiver side.
    Error getting receiver side at communication channel :
    Message processing failed. Cause: com.sap.aii.af.ra.ms.api.RecoverableException:
    Yeswanth.txt: Cannot create a file when that file already exists. : com.sap.aii.adapter.file.ftp.FTPEx: 550
    Yeswanth.txt: Cannot create a file when that file already exists.
    Reward points for useful answers.
    Regards,
    Yeswanth.
    Edited by: YeswanthRaj Kumar on May 23, 2008 8:20 AM

    Hi Yeswanth
    Then you can try with a "Add Counter". This will create new file each time with the same name but a counter will be added to the file name at the end specifying the number of times it is created.
    You can also the specify the format to create the counter once select this option u can correspondingly fill the Format and step fields.
    Will this be fine.
    Regards
    Ashmi

  • I cannot attach pdf files in Outlook. Just started yesterday. I need a fix as I use this alot.

    I cannot attach pdf files in Outlook. Just started yesterday. I need a fix as I use this alot.

    You can experiment with how Firefox would run after a reset or reinstall by creating a new profile.
    A new profile will have your system-installed plugins (e.g., Flash) and extensions (e.g., security suite toolbars), but no themes, other extensions, or other customizations. It also should have completely fresh settings databases and a fresh cache folder.
    Exit Firefox and start up in the Profile Manager using Start > search box (or Run):
    firefox.exe -P
    Any time you want to switch profiles, exit Firefox and return to this dialog.
    You'll click the Create Profile button. I recommend using the default location suggested (in other words, don't click the button to choose a different folder). Then start Firefox in the new profile you created.
    After Firefox settles down, try Outlook. Any luck?
    If it works, log out of Outlook, exit Firefox, restart it and check again. If it doesn't work the second time, one possible explanation is a a system-installed add-on getting picked up or activated.
    When returning to the Profile Manager, you might be tempted to use the Delete Profile button. But... it's a bit too easy to accidentally delete your "real" profile, so I recommend resisting the temptation. If you do want to clean up later, I suggest making a backup of all your profiles first in case something were to go wrong.

  • I just burned to disc an album of photos I created in Pages but I cannot open the file on the disc because "the format is not valid".  What does this mean and how do I correct it ?

    I just burned to disc an album of photos I created in Pages but I cannot open the file on the disc because "the format is not valid".  What does this mean and how do I correct it ?

    There are numerous thread about the same matter in this forum
    I hope you'll find your answer
    https://discussions.apple.com/search.jspa?resultTypes=&dateRange=all&peopleEnabl ed=true&q=the+format+is+not+valid&containerType=14&container=2084&username=&rank By=relevance&numResults=15

  • I just began month trial of cs6 & cannot open raw files from nikon 600?

    I just began month trial of cs6 & cannot open raw files from nikon 600?

    Have you updated your Photoshop to get the latest Camera Raw update patch?  If not go to:
    Help >> Updates
    This should get you the necessary updates for your camera assuming it is not "too recent".
    Good luck and post back.

  • I cannot open reader files (most often but receive a blank screen.  If I email to another macbook air it opens just fine.  I downloaded latest version.

    I cannot open reader files (most often but receive a blank screen.  If I email to another macbook air it opens just fine.  I downloaded latest version.

    Hi TheMom1999,
    Do you mean that you are unable to open the pdf files via Reader?
    Which OS are you using? Have you updated Reader o v. 11.0.7 and checked?
    Was it working fine for you before?
    Regards,
    Rave

  • On every URL link in Microsoft Outlook I get the message that "The system cannot find the file specified." Then it proceeds to open it AFTER I close the error message. I just updated Firefox a few days ago and it began then and continues.

    It shouldn't take any more detail than this. This is what happens every time:
    "Generald failure: The URL was 'http: //link.washingtonpost.com/r.....' The file system cannot find the file specified."
    '''EVERY URL'''

    See:
    * http://kb.mozillazine.org/Windows_error_opening_Internet_shortcut_or_local_HTML_file_-_Firefox

  • My Windows7 PC just crashed.  I have the files backed up online with Carbonite.  I want to buy a Mac I book.  Carbonite says it cannot download pc files to a Mac.  Is there a solution?

    My Windows7 PC crashed and I have the files backed up online with Carbonite.  I want to buy a Mac I book.  Carbonite says it cannot download pc files to a Mac.  Is there a solution?

    Brilliant, that clears things up - there is a single
    audio in that is next to the PC in so I guess I need
    one of the single cables you have mentioned,
    hopefully the Apple Store can point me in the right
    direction when I go in to buy my Mini.
    If the TV has a single minijack-type audio input, then the cable you need is a very standard one that can be found almost anywhere that cables for audio/home theatre systems are sold. In the old days it would be easy to point you towards the nearest Tandy, but as I understand it they're now gone. However, even supermarkets such as Tesco are likely to have something this basic!
    No doubt Apple will release an Intel Core 2 Duo
    version the day after I pick it up.
    There's no doubt that at some point Apple will revise the range and make new mini's faster or more powerful - and it may be that it happens next week at the Macworld Expo. I'd bet there are a few people holding on for a few days to see if new minis are announced there, and you might want to do the same if it's of concern, but the existing models are plenty powerful, and more than enough for most user's needs.
    Thanks for all your help, much appreciated.
    You are most welcome - and please come back and post again if you have any further questions or any problems once you've got your system!

  • Reading, comparing and appending two files is taking lot of time

    public static void main(String args[])
         BufferedReader bSource = null;
         String sSource="";
         String sSourceData="";
         BufferedReader bDestination = null;
         String sDestination="";
         String sDestinationData="";
         try
              bSource = new BufferedReader(new FileReader("C:/TEMP/Source.map"));
              while((sSource = bSource.readLine()) != null)
                   sSourceData+=sSource;
              bDestination = new BufferedReader(new FileReader("D:/TEMP/Destination.map"));
              while((sDestination = bDestination.readLine()) != null)
                   sDestinationData+=sDestination;
         catch(IOException ioe)
              System.out.println(ioe.getMessage());
         finally
              try
                   bSource.close();
                   bDestination.close();
              catch(Exception e)
         if(sDestinationData.contains(sSourceData))
              fDestinationFlag=false;
         else
              fDestinationFlag=true;
         if(fDestinationFlag)
              BufferedReader br2 = null;
              BufferedWriter bw2 = null;
              try
                   br2 = new BufferedReader(new FileReader("C:/TEMP/Source.map"));     
                   bw2 = new BufferedWriter(new FileWriter("D:/TEMP/Destination.map",true));
                   while((line2 = br2.readLine()) != null)
                        bw2.write(line2);
                        bw2.newLine();
                        bw2.flush(); 
              catch(IOException ioe)
                   System.out.println(ioe.getMessage());
              finally
                   try
                        br2.close();
                   catch(Exception e)
                   try
                        bw2.close();
                   catch(Exception e)
    }I am comparing the contents of the two files Source.map (containing 3 lines) and Destination.map (containing 5000+ lines). The contents of the Source.map gets appended in the Destination.map only if it does not contain the same.
    Now my program is doing the necessary, but it is taking lot of time. It's taking 1 min 26 seconds.
    Could anyone please tell me what do I modify in may program to make it execute much faster.

    1) Just compare the byte content - no need to convert to Strings.
    2) Compare a block (say 256K bytes) at a time - no need to read the whole file into memory.
    3) Compare the file lengths first - if they are different then the content cannot be the same.
    4) When appending one file to the other, set the 'append' flag in the constructor of FileOutputStream to true.

Maybe you are looking for

  • Publish prerecorded video or image, instead of Camera in ActionScript3 via RTMP to FMS

    I'm looking for a way to stream video or image from the desktop to an FMS installation, in the case it does not exist a webcam or a mic. I know that in ActionScript, it's possible to do: netStream.attachCamera(camera); netStream.attachAudio(mic); but

  • How do I change the printable space in the 1510?

    I've changed the margins in my Word document (T: .3; B: .3: R and L: .5), but the doesn't recognize it and cuts off the first two lines.  How can I change the printer's print margins?  I have Windows 7. This question was solved. View Solution.

  • Error 550 5.7.1 Rcpt command failed: Mail denied due to site`s policy

    Hi, I have a problem with my ocs, i cannot send mail to outside domains from outside my network. What i want to do is to be able to allow a few users to send emails from anywhere (any ip) as long as they use auth because they are mobile users (black

  • How to find my podcast page in iTunes??

    Hello everyone, I have made a video podcast and have tried searching for it in iTunes music store so I can link directly to it from my webpage. When I search my name, or the name of the blog, I always get "no results". I created this with Blogger and

  • Why is the GPRS symbol an "o" and not a "G"?

    Hi In the UK, if there is no 3G coverage, the next best thing is GPRS. EDGE coverage is extremely sparse, so when I don't get 3G, the "o" symbol appears for GPRS. My question is simple... why have Apple chosen the symbol to be an "o" rather than a "G