Copy one text file to another text file and delete last line

Hi all wonder if someone can help, i want to be able to copy one text file to another text file and remove the last line of the first text file. So currently i have this method:
Writer output = null;
         File file = new File("playerData.xml");
         try {
               output = new BufferedWriter(new FileWriter(file, true));
               output.write("\t" + "<player>" + "\n");
               output.write("\t" + "\t" + "<playerName>" + playerName + "</playerName>" + "\n");
               output.write("\t" + "\t" + "<playerScore>" + pointCount + "</playerScore>" + "\n");
               output.write("\t" + "\t" + "<playerTime>" + minutes + " minutes " + seconds + " seconds" + "</playerTime>" + "\n");
               output.write("\t" + "</player>" + "\n");
               output.write("</indianaTuxPlayer>" + "\n");
              output.close();
              System.out.println("Player data saved!");
         catch (IOException e) {
               e.printStackTrace();
          }However each time the method is run i get the "</indianaTuxPlayer>" line repeated, now when i come to read this in as a java file i get errors becuase its not well formed. So my idea is to copy the original file, remove the last line of that file, so the </indianaTuxPlayer> line and then add this to a new file with the next data saved in it. So i would end up with something like this:
<?xml version="1.0" encoding="UTF-8"?>
<indianaTuxPlayers>
     <player>
          <playerName>Default Player</playerName>
          <playerScore>0</playerScore>
          <playerTime>null minutes null seconds</playerTime>
     </player>
     <player>
          <playerName>Default Player</playerName>
          <playerScore>0</playerScore>
          <playerTime>null minutes null seconds</playerTime>
     </player>
     <player>
          <playerName>Default Player</playerName>
          <playerScore>0</playerScore>
          <playerTime>null minutes null seconds</playerTime>
     </player>
</indianaTuxPlayers>
However after all day searching the internet and trying ways, i have been unable to get anything working, could anyone give me a hand please?

I would go the XML route too, but for fun, open a file as a BufferedWriter and do this:
void copyAllButLastLine(File src, BufferedWriter tgt) throws IOException {
    BufferedReader in = new BufferedReader(new FileReader(src));
    try {
        String previous= in.readLine();
        for (String current = null; (current = in.readLine()) != null; previous=current) {
            tgt.write(previous);
            tgt.newLine();
    } finally {
        in.close();
}

Similar Messages

  • Can I copy one frame of a movie using iMove and save the frame as a file that can be printed like a picture?

    Can I copy one frame of a movie using iMovie and save the frame as a file that can be printed like a picture?  If so, how do I do that?

    You could if you want a postcard sized print.
    Printers need a lot more "dots" per inch and even a 1920X1080 video doesn't have enough "dots" to make more than a postcard.
    Look at the "More Like This" links at the right side of this page for instructions.

  • Why does the same RGB color appear lighter in one ai file and darker in another?

    Why does the same RGB color appear lighter in one ai file and darker in another??  I want to use the more vibrant color, but when I try to reproduce the same RGB color code in another Adobe Illustrator (ai) file, it shows up darker.  I printed the two files out, and you can see the difference in the print too.  I exported the color orginally as an eps file from an ArcGIS map.
    Any insight is greatly appreciated!
    Anne

    You illustrator files may have different color profiles attached.
    Set to show your color profile in the bottom left of each document by using the flyout menu >> show >> document color profile
    Then you can use edit >> assign profile to get them the same
    Yours are quite far off for RGB (which are usually close to each other for many profile due to wide gamut).  I question as Jacob did if one of your documents are in CMYK mode. Look in parenthesis after the document name at top of window.
    Check if view > proof setup is the same (do not use the uncoated profile as in my screenshot, that was only there cause of my testing)
    Make sure view >> proofs colors is checked or unchecked for both.
    To get them to print the same, check these settings are the same
    Sorry for all the screenshots, but hopefully one day we will see Adobe's complex color management united all in one window.

  • Copying one .eas file for multiple sprite sheets.

    Hi, I've been googling the web trying to find answer to a problem but haven't found a solution yet. Maybe someone here has an idea.
    I'm working on a project with Edge Animate CC where I'm creating a multitude of different animated symbols from sprite sheets. The symbols/sprites, which there are a lot of, come in sets, each with a different character wearing different colour clothes. For example, there's one of a man in a white shirt walking, and then the same man in a blue shirt, a red shirt, and so on, and then the same for several other characters. Because each version of each character is the same except for a colour change, I've been trying to create one sprite sheet from Flash CC, make colour edits to the sprite sheet in Photoshop CC, save it with a new name, then import it into Edge Animate using the same spritesheet.
    It seems straightforward enough but what I've learned is you can't use an .eas file with spritesheets other than the one it was created with in Flash. When I try it says the .eas file and the image don't match, and to check the paths for both files. When I copy the .eas file and rename it, giving it the same name as the new sprite sheet I want it to work with, I still get the same message. When I open up that .eas file in TextEdit and change the "image" filename in the "meta" section to correspond to that of the new sprite sheet, it still doesn't work. I don't see anything else within the .eas file that would tie it to any particular spritesheet, so between making that change and changing it's filename I would expect the .eas file would work the new sprite sheet.
    I know I could create sprite sheets for each colour scheme of each character through Flash, but since they are all identical other than their colour it would save me a ton of time to just copy and edit the sprite sheets. The colour changes are not something I could do within Edge Animate.
    Has anyone had similar issues? Any tips?
    -A

    Hi Medley, Good to see that you are experimenting with the new SpriteSheet feature available in Animate CC 2014.
    Some points:
    The EAS file format is currently only supported from Flash Pro CC 2014. There are some meta data tags that is read when you bring in an eas type spritesheet and therefore Animate will be able to import only the sprite sheets created from Flash Pro CC using the EAS route.
    If you want to use spritesheets from other applications like photoshop, I would recommend that you don't enable the "load an eas file" check-box. In this case the sprite sheet PNG will be the only input that you need to specify in the Import dialog.
    In this case you will need to have a sprite-sheet which has the individual sprites that is stacked out in order from left to right and top to bottom. You can then specify the rows and columns and the padding options in the Spritesheet import dialog in animate.
    Let me know if this works for you.
    -Sujai

  • Can I copy my iTunes files and folders to Time Capsule wirelessly from my PC?

    Can I copy my iTunes files and folders to Time Capsule wirelessly from my PC? I was wondering since my iTunes files and folders are connected to iTunes.

    You can but the TC is the worst possible location. The design is slow to start and quick to stop data connections.. that will cause trouble.
    Moving folders has specific instructions.
    http://support.apple.com/kb/ht1364
    Move it to an external hard disk fine.. but be very sure you will not be happy with the TC as a location.

  • How can I save my keynote presentation as one single file and not a folder

    I use the latest kerynote version and I would like to upload the presentation as a single file to a collaboration solution.
    How can I save my presentation as one single file and not as a folder?

    Keynote "files" are not single files, they are packages which contain all the individual files that the presentation requires.
    Some online storage systems such as Google Drive show Keynote as a folder.
    We use Dropbox to distribute all our file types and Keynote does not have an issue using that.

  • I dragged my notes from one iCloud account to another iCloud account and they disappeared.  How do I find them?

    I dragged my notes from one iCloud account to another iCloud account and they disappeared.  How do I find them?

    Hello reallilybart,
    Thank you for the question. You can export the calendar events from your previous iCloud account and then import them into your new iCloud account.
    First, use these steps to export your events from your original account and make note of where you save the file to:
    Export a calendar’s events
    In Calendar, click the calendar’s name.If you don’t see your calendars, click Calendars.
    Choose File > Export > Export.
    Choose a location for the file, and then click Export. The events are exported in an iCalendar (.ics) file.
    Next, quit the Calendar application, and log out of your original iCloud account in System Preferences > iCloud.  Then log in with your new iCloud account and open Calendar.  The final step is to import the file into the calendar for your new iCloud account
    Use these steps to import the calendar events:
    Import events into a calendar
    If you want, create a new calendar for the events.Add or delete a calendar
    Choose File > Import > Import.
    Locate and select the calendar file that contains the events, and then click Import.
    Choose the calendar you created or another calendar to add the events to.
    You can also drag a .ics file to Calendar. The events in the file are added to the calendar that’s highlighted in the Calendar list.
    You can find the full article here:
    Calendar: Export and import calendars
    http://support.apple.com/kb/PH11524
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • TS1277 after installing itunes, my computer won't recognize my cdrom/burner any longer.  Worked  ok before and I have uninstalled itunes and it works again and when I reinstall itunes it won't work again.  I have also went into registry files and deleted

    After installing itunes, my desktop computer doesn't recognize my internal cd rom/burner.  I removed itunes and it works ok and when I reinstall itunes it won't work again.  I went into the windows registry files and deleted the lower filter which is one correction for this and it worked ok until the next itunes upgrade and now it won't work again.  If anyone knows what to do please let me know.  My device manager shows a code "10"

    My device manager shows a code "10"
    That suggests an AFS.sys issue. But we'd better doublecheck.
    Could you post your diagnostics for us please?
    In iTunes, go "Help > Run Diagnostics". (If you're running iTunes 11.0.x you'll need to bring up your menu bar first to see the Help menu.) Uncheck the boxes other than DVD/CD tests, as per the following screenshot:
    ... and click "Next".
    When you get through to the final screen:
    ... click the "Copy to Clipboard" button and paste the diagnostics into a reply here. (Use your Ctrl-V keyboard shortcut to paste.)

  • TS4036 how can I view backed up files and delete things I don't need

    how do I view backed up files and delete thing I don't need

    You can't view individual files contained in the backup.  You can control which apps are backed up, and whether or not the camera roll is included in the backup, by going to Settings>iCloud>Storage & Backup>Manage Storage, tapping the name of your device under Backups, then looking under Backup Options.

  • VBScript to read the content of a .csv file and delete old files mentioned in the .csv

    I have a Windows 2003 file server.
    I have generated a report in .csv format, about the files which are older than 1 year.
    I need a VBScript to read the .csv file and delete the files which are enlisted there.
    Can someone please help me with this?

    Look into the "Learn" link above.  There are resources and instructions on how to write VBScript code.  Look into how to use the FileSystemObject.
    ¯\_(ツ)_/¯

  • Adobe Create PDF, my main usage is to combine 2 files and delet part of it, can I do That?

    I want to suscribe to Adobe Create PDF, my main usage is to combine 2 files and delet part of it, can I do That?

    Hi mzf35k,
    CreatePDF would enable you to combine two files however you might not be able to delete from the existing file. You need to make modification(delete) in the source file.
    Or you can purchase the full Acrobat or subscription for Acrobat to perform the desired task with PDFs.(Please visit the link)
    http://www.adobe.com/products/acrobat.html?promoid=JOLIR
    (Acrobat Full)
    http://helpx.adobe.com/x-productkb/policy-pricing/acrobat-pro-xi-subscription-faqs.html#id _53052
    (Know about Acrobat Subscription)
    ~Pranav

  • I am trying to delete one entry in forms data by highlighting and deleting it but it is not working. Thanks.

    I am trying to delete one entry in forms data by highlighting and deleting it but it is not working. Thank

    Lightroom - all versions
    Windows
    http://www.adobe.com/support/downloads/product.jsp?product=113&platform=Windows
    Mac
    http://www.adobe.com/support/downloads/product.jsp?product=113&platform=Macintosh

  • Copying a flash file and pasting into another one...

    I want to copy a .swf file I have and paste it into another one, frames and all.  I have tried but nothing gets copied over correctly.  Either that or my buttons are on a single frame.. and no longer act like a button with the -Over-Up-Down-Hit frames.  Can this be done? please help...
    Thanks Guys,
    -Dedikation-

    Select all of the timeline frame, right click the selection and choose Copy FRames.  In the other file, Insert -> New Symbol -> MovieClip... etc...  select the one keyframe in the empty movieclip's only layer, right click the selection and choose Paste Frames.  All layers and frames should paste in as they were copied.

  • Searching a text file and printing the line if found!

    Hi, Im fairly new to JAVA and have been googling this for hours and havent found any results that
    have helped me...
    Im looking to search a text file for a value that is in a that is delimited by colons
    eg 45787 : 398948 : 398884 : 398984
    IF that value is found I need to print this entire line and move it into a string.
    I can work out the delimit part, the problem for me is a)searching the text file
    and b) tell java to print that line only??
    Any help would be very very much appreciated
    Cheers
    James

      public void printCourses() throws Exception
                stuinput[] courseObjArray = new stuinput[10]; //Make sure this is the same as the ammount in the text
                   Scanner sc = new Scanner(new File("testfile.txt"));
                   int i=0;
                   boolean found = false;
                   while(sc.hasNextLine())
                   //Delimit this line with scanner
                   Scanner sc1 = new Scanner(sc.nextLine());
                   sc1.useDelimiter(":");
                   courseObjArray[i] = new stuinput(sc1.next(),sc1.next());
                   i++;
                   }//while
                   for(int i1 = 0;i1 < courseObjArray.length;i1++)
                   System.out.println(courseObjArray[i1].courseCode);
                   System.out.println(courseObjArray[i1].courseName);
                   System.out.println(courseObjArray[i1].courseName);
                   System.out.println("-----------------");     
                   String courseCode2 = "courseObjArray[i1].courseCode";
                   if (courseCode2  == "12345")
                        System.out.println("working");
                   else{System.out.println("Not Found");}
           }hmmm just wondering why could this method always return a "Not Found"....if the text file had a whole bunch of values like this
    12345:Course1
    12344:Course2
    12343:Course3
    isnt it surposed to return 1 "Working"?? because there is a 12345 in on of the line, in the semi colon delimited line with 2 values, one being the course code, one being the course name??
    Given that there is 10 lines (from Array Object)

  • How to copy folder with files and subfolders within it  to another folder

    how to copy a folder with files and subfolders within it to another folder

    http://javaalmanac.com/egs/java.io/CopyDir.html?l=new

Maybe you are looking for

  • Assigning learners to Learner Group and creation of Learner Group.

    Hi All, Are there any standard ways to create Learner Groups from R12.1.3. I have tried looking for Oracle standard APIs but did not find them. Is there any other way we can create Learner group from back end. I know to create them from Application b

  • Cannot install illustrator on my mac 10.7.5, help??

    I've tried downloading the 30 day free trial and the adobe installer opens up but barely has any progress on the installer bar. i have a mac that runs 10.7.5 can anyone help?

  • System hang after clicking "Run" to launch "SBO_Welcome.hta"

    Hi, My client encounters a pop up window "Open File - Security Warning" upon logging into SAP. It is a message to run "SBO_Welcome.hta" which is located on " SERVER\B1_SHR\Help\EN". When the "Run" button is clicked to launch the above mentioned file,

  • How do I change the font in my project?

    Is there a way to remap all instances of a font in After Effects? Just like in Flash when my machine can't find the version of the font it needs, I have the option to remap that font to a different typeface, instead of having to go through every laye

  • The iPhone cannot be synced. An unknown error occurred (13109)

    I am not able to sync my iPhone 3G to iTunes. Running iTunes 8.2 and the 3.0 update on my iPhone. Genius is turned off and I tried restarting the phone and iTunes several times. Any advice? Thanks, Goran