PrintWriter appending when I don't want it to

Hi!
I am calling a function that looks something like this:
public void func() {
     PrintWriter outFile = null;
     try {
          outFile = new PrintWriter(new BufferedWriter(new FileWriter("test.txt"));
     } catch (IOException e){}
     for (int i=0; i<100; i++)
          outFile.println("test");
     outFile.close();
}The problem is that if I call the function twice, it will just appened new lines, so it will have 200 lines. The third time it will get 300 lines and so on. I just want the function to "clear" the file and start from the beginning each time I call it. How do I do that?
Thanks!

Thanks warnerja. You hit the nail on the head. I read your line, took myself 5 seconds to go and read something in the code, and I found the problem right away(I've also been taking a break, that might have helped some ;))
The above code was simplified. What I really did was to loop through a LinkedList for strings and printed it out. Problem was, that when I ran that code again, I added the exact same set of strings to the list. Doh!
Joachim, I did try the append, but it is defaulted to false so that didn't help anyway. But as stated above, it's solved :)
Thanks a ton guys/girls!

Similar Messages

  • How can I prevent Magic Mouse from scrolling horizontally when I don't want it to?

    I recently purchased a Magic Mouse to go with OS 10.6 Snow Leopard. It's a great mouse but it causes 2 problems:
    If I leave it on "Scroll with interia" in System Preferences/Mouse, it scrolls horizontally when I don't want it to.  Since I mostly work in Word documents, I often lose my place in the document this way. On the other hand, checking "Scroll without inertia" makes vertical scrolling, which I do all the time, a lot harder.
    The mouse seems to cause what I think of as "fractures" in Word documents--words and parts of sentences will disappear or get crunched together , then reappear when I select the place where they vanished.  They also reappear if I scroll vertically to get the problem area off the screen and then return to it. This wastes a lot of time at best; at worst, I'm afraid I'll lose work.  The problem occurred once in a while with a Logitech bluetooth mouse I was using, but not as bad and not all the time.
    I love the mouse's ergonomics and would like to keep it, but if I can't solve this problem, I'll have to return it.  Would be very, very grateful for any tips!  Thanks.

    Always nervous about recommending sites I have no personal experience of.  On the plus side it doesn't relate to any of the bad sites I am familiar with and it appears to be the developer's site ... but there is no contact point for you to ask questions.  You said in your initial post it was to go with Snow Leopard but this version says it is meant for 10.7 and above.   Did you notice that?   I also notice several other references to Word and mouse and one person found the solution lay in the updating of word 2011 to its highest level.   I can offer no more.

  • Why Does Save As-PDF/A reduce file size when I don't want it to?

    I scanned a 4-paged printed card with my Epson Perfection 4490 scanner in order to digitally archive it. Each page is about 5x7 inches, and I scanned at 100 percent. I scanned each page as an individual TIFF image file, at 600 samples per inch.
    I brought each TIFF image file into Photoshop one at a time. I saved each TIFF as a JPEG, at Quality: 8, Baseline ("Standard").
    Then, I brought the JPEG's into Adobe Acrobat Pro to create a 4-paged PDF. Initially, the file size of the saved 4-paged PDF was 5 MB. (Later, I determined the individual JPEG's add up to 5.2 MB.) When saving as PDF/A, the final format that I want to use, the file size was unexpectedly reduced from 5 MB to 2.5 MB.
    What is the reason for the file size being reduced to 2.5 MB? I had already done the compression that I wanted in Photoshop. The PDF was not downsampled. I purposely did not use Optimizer.
    I did a test. This time, in Photoshop, I compressed each TIFF to JPEG, at Quality: 5, Baseline ("Standard"), the Medium setting instead of the High setting. After bringing these JPEG's into Adobe Acrobat Pro, the saved 4-paged PDF was 2.8 MB in size, an expected smaller size. Saving as PDF/A produced a file of 2.6 MB in size, very close to the same size this time, possibly indicating it accepting the Medium quality level.
    Apparently, saving as PDF/A reduces the quality level of JPEG's to Medium quality, when they are of higher quality to begin with. It seems to be designed to optimize even when I don't want it to.

    Here's the Audit Space Usage for the original 5 MB file. It shows the images taking up the majority of the space, as expected:

  • Iam using a table in numbers to plot daily graph lines. If I fill a cell with a text box  at say zero it plots the graph. I can't actually set the cell value until the actual day but the graph plots it at zero when I don't want it to plot anything. Is tho

    I am using a table in Numbers to plot daily graph lines. Mood swings of how I am on the day, i"m a depressive.
    If I fill a cell with a step box at say zero it plots the graph. I can't actually set the cell value until the actual day but the graph plots it at zero when I don't want it to plot anything. Is there a work around. so thatbgraph only plots on the day?

    The answer is (sort of) in your subject, but edited out of the problem statement in the body of your message.
    When you use a stepper or a slider, the value in the cell is always numeric, and is always placed on the chart if that cell is included in the range graphed by the chart.
    But if you use a pop-up menu cell, you can specify numeric or text values in the list of choices for in the menu. Numeric values will be shown on the chart. Text values will not.
    For the example, the values list for the pop-up menu was:
    5
    3
    1
    Choose
    -1
    -3
    -5
    The first pop-up was set to display Choose, then the cell was filled down the rest of the column. Any text value (including a single space, if you want the cell to appear blank) may be used instead of Choose.
    For charts with negative Y values, the X axis will not automatically appear at Y=0. If your value set will include negative values, I would suggest setting the Y axis maximum and minimum to the maximum and minimum values on your menu list, rather than letting Numbers decide what range to include on the chart. Place a line shape across the chart at the zero level, and choose to NOT show the X axis.
    Regards,
    Barry

  • How do I stop the screen from magnifying or zooming in when I don't want it to?

    The screen keeps enlarging when I don't want it to.  How can I turn off this function in Lion?

    There are a few ways to get the screen to "enlarge", so it depends on what you are doing to make it happen.
    For example, on a trackpad you can double-tap (not click) with two fingers to zoom in web pages.  Or you can slide two fingers in a spreading out fashion to zoom in.
    Do you have any notion about what you are doing when the undesired enlarging occurs?
    charlie

  • How do I turn off Firefox checking for updates (I am fed up with Firefox continually asking to update when I don't want to due to previous bad experiences)

    I would like to turn off firefox checking for updates
    I don't want to update due to previous bad experiences with updates (version 4 and version 5)
    I am frustrated by being reminded on a daily basis to update when I don't want to

    Use
    *'''Firefox button -> Options -> |Advanced | -> |Update|''' and uncheck the update option, or opt to ask first.
    * see [[Options window - Advanced panel#w_update-tab]]_update-tab
    * and to downgrade
    **[[installing a previous version of Firefox]]
    ** and the download itself [http://www.mozilla.com/en-US/firefox/all-older.html]
    Also note that currently
    * firefox 3.6 is still supported, and has had recent security updates
    * plans are to continue supporting it despite any comment on the download page
    **(not sure how long for but see https://wiki.mozilla.org/Firefox/Planning/2011-09-07#Questions.2C_Comments.2C_FYI ) confirming continuing support for Firefox 3.6
    * Firefox 3.6 has updated with security fixes, so is I think now 3.6.22 ; but it is NOT currently trying to upgrade its users to the current firefox release (Firefox 6)

  • Why am I always forced to upgrade Firefox when I don't want to?

    I asked this question once b4, & never got a response. Probably because Firefox sucks royally, & they're afraid to answer my question. I'm always forced to upgrade Firefox when I don't want to. I get this stupid little pop-up for 1-4 days saying the new version is available. I ignore it, & without warning upon starting up my computer, Firefox upgrades itself. First of all, I F'ING H8 THAT! Second of all, I WANT TO MAKE THE BLOODY CHOICE WHETHER OR NOT I WANT ANOTHER SUBSTANDARD FIREFOX UPGRADE!! The ONLY reason I stay w/Firefox is that IE sucks even more, & you can't play any Facebook games w/IE. Firefox dev's, I realize I'm just an insignificant user & you don't really care about any of us, but really, must you force us to upgrade? Hmmm, I may just move on over to Chrome.

    You can turn off automatic updates, for details see the "Configuring update options" section of this article - https://support.mozilla.com/kb/Updating+Firefox
    Turning off automatic updates in Chrome is not as easy, it involved editing the registry.

  • When I use the keyboard on my iphone 5, the keyboard takes a mind of its own.  If I press a letter sometimeIs it puts the letter twice.  It puts periods when I don't want it to.  And if I hesitate on a letter it starts erasing everything I just typed.

    When I use the keyboard on my iphone 5, the keyboard takes a mind of its own.  If I press a letter sometimes it puts the letter twice.  It puts periods when I don't want it to and if I hesitate, the keyboard starts erasing everything I just typed.  Is there a setting I need to change to make this go away?

    What user troubleshooting have you tried? The user troubleshooting steps are restart, reset, restore from backup and restore as new. Usually a reset will fix most of the unusual actions by the device.

  • My wifi keeps coming on when i don't want it to. How do i disable it and keep it off?

    My wifi keeps coming on when i don't want it to. How do i disable it and keep it off?

    kcquestions,
    That's a very good question! It's important to be on the network you want to be on. How are you turning the wi-fi off? If you go into your settings there should be a wi-fi switch as the second option from the top. If we turn it off there it shouldn't come back on until you tell it to. If you select that and press the menu button (3 dots in the top right corner) you can also turn off "Allow wi-fi scanning" which can help not get notified of them when wi-fi is off.
    AndrewT_VZW
    Follow us on Twitter @VZWSupport
    If my response answered your question please click the �Correct Answer� button under my response. This ensures others can benefit from our conversation. Thanks in advance for your help with this!!

  • ITunes 8 keeps randomly opening when I don't want it to.

    I just downloaded the new iTunes 8 yesterday, and today while working on my computer, iTunes Randomly opens up when i don't click on it or anything. is there anyway to make this stop or how can i get the old version of itunes back?

    I have to agree. I've been using iTunes/iPods exclusively for listening to podcasts since 2008, and within the past year it's just gotten increasingly frustrating and confusing to use both iTunes and my iPod for this purpose. I just found this thread because my iPod auto-deleted a podcast that I'd only listened to for 10 minutes; and I don't want it to ever delete podcasts without my consent. Truly infuriating.

  • FireFox does SESSION RESTORE when I don't want it to

    I made sure I set everything to go back to my homepage:
    Options, General, When Firefox starts : Show my homepage
    (Google news)
    But:
    When I watch msnbc news from their streaming window, I continue to surf the net, while keeping msnbc's video window open (I like to listen to the news when I surf the web).
    When I'm done viewing a site I close the webpage (but keeping nsmbc's video window open). When I re open Firefox, it will go to the last page I viewed, not my homepage.

    Once I had the problem that firefox was opening the pop-up windows even when I didn't want them to be opened. Well I don't know how I corrected the problem. I think you should try to reset your settings and then try again.

  • Face time activates when I don't want it to

    FaceTime is activating on it's own how can I fix this

    I don't want to use face time and even when I deactivated it still works it happens when I'm talking on the phone and it will face time with the person I'm talking to a little activate to someone else in my address book and I've tried to block it but it doesn't block just faced time

  • Firefox blocks popups when I don't want it to

    I had to reset Firefox and it works fine now with one exception: It blocks popups even though I don't want it to. I have unchecked the box in Options that relates to blocking popups. I have rebooted several times all to no avail. Practically every web site I seek is blocked until I hit the "allow" button that appears when I try to open the site. I can't find anything in the tech docs to answer this question and don't know where else to look.

    Once I had the problem that firefox was opening the pop-up windows even when I didn't want them to be opened. Well I don't know how I corrected the problem. I think you should try to reset your settings and then try again.

  • Gmail won't send messages, and Mail shows sent messages when I don't want

    I have my Gmail account set up through the Mail application. I can receive messages fine but I can't send them. So I send them by actually logging into Gmail. Now when I send them that way, they show up in my Mail account but i don't want them to. Help please!

    I am having the same problem. I have tried Mulder's solution without success.
    Here is some background:
    I have two gmail accounts. My normal "[email protected]" account with which I am using POP does send mail. However I also have a google apps account ("username@my_domain.com") connected with IMAP and I can't send using this one. I have tried the various ports suggested by gmail help. It won't connect with the outgoing server. I ran a Telnet test and my computer is connecting with the server, but it appears as "offline" in Mail. User authentification and SSL are both checked (although I have also tried unchecking them).

  • Mighty mouse annoyance - brings up contextual menus when I don't want them

    This is a mighty annoyance. For some reason my almighty mouse has decided that every time I click, it's going to present me with a contextual menu which I don't want to see.
    How can I stop this from happening?

    You disable the right-click option by going to System Preferences, clicking on Mouse, and adjusting the appropriate settings. Then just use Control-click to bring up the contexual menu when you need it.

Maybe you are looking for