Delete last line of a textfile without putting the whole file in memory

Hello!
I want to delete the last line of a text file without loading the whole text file into thememory. My problem is as follows:
A algorithm generates output that has to be written into a text file. This happens periodically - the output goes straight into a xml file. The xml file looks like this:
<test>
<step>
<time>2006-06-19 10:55:20</time>
<result>12321</result>
</step>
<step>
<time>2006-06-19 10:58:20</time>
<result>41515</result>
</step>
</test>
The XML file must be valid, so I have to delete the last line ("</test>") before I add a new <step>-section.
Many thanks in advance
Kind regards,
buliwyf

For processing in a separate tool which understands XML, then using a DTD to declare an external entity is often better - you wrap the entity in the document root element, so you can just append to the end of the file the entity references and not bother about inserting before the closing tag.
File other app loads:
<?xml version="1.0"?>
<!DOCTYPE test [ <!ENTITY content SYSTEM "content.xmlfragment"> ]>
<test>&content;</test>File content.xmlfragment which can be simple appended to:
<step time="2006-06-19 10:55:20">12321</step>
<step time="2007-04-09 10:55:20">12321</step>
<step time="2008-09-26 00:03:20">12321</step>If you can't use XML to solve the problem, then you can scan backwards in the file (using random access file or file buffer) until you find a '<' character which is followed by an '/' character. You can't have CDATA after the closing tag of the document element, and comments and processing instructions have different characters following the '<'.

Similar Messages

  • How to put the ".class" file in Memory with Javac?

    The J2SE 6 RC have an tool : javax.tools.JavaComplier. I can use it to compile the source code in memory( I implemented an JavaFileObject).
    But the compiler aways put the output file(.class) to file system. It;s not my want to do . I am writing an IDE ,I use javac to determine the code error after the user's typing. So complier is used a lot , writing to file system is a time consuming job.
    I also want to use the byte code(".class" file) for reflection , so if the JavaCompiler can put the output file in memory and then I can reflect it.
    My current solution is puting the output file to file system then use Class.forName() to reload it in memory then reflect it. It seems a useless IO operation with file system.
    How can I do with it?
    Thanks!

    Those 'useless' I/O operations are one or two out of thousands that are implied by compiling a Java source file.
    I wouldn't worry about it.

  • Loadjava puts the whole program on one line

    Hi,
    I have used the loadjava facility standalone and within Oracle9i jDeveloper and found that when I upload the java source, it puts the whole program on one line. Also if I have left blank lines in the source code, they appear as 'null' in the stored procedure.
    See below is my code:
    package mypackage1;
    public class HelloWorld
       public static String world ()
          return "Hello world";
    }and this is what it looks like if I open the Java classes in jDeveloper:
    package mypackage1;nullpublic class HelloWorld{   public static String world ()   {      return "Hello world";   }}nullI am using a windoes 2000 box.
    Why is this happening?
    Thanks
    Jag

    Thanks, i'll try it out,
    However, it isn't just the code that appears on one line. All teh functions and packages all appear on one line and they are generated either by JDev and hence are out of my control.
    You would have thought that this would have been one of the types of things the JDeveloper development team would have tested, so i'm hoping it just a configuration somewhere.
    Thanks
    Jag

  • I have all my devices connected to iCloud.  I would like a reduced contact list on my iPhone without removing any from my master list on my computer.  How do I delete contact numbers from my phone without disrupting the master list on my computer?

    I have all my devices connected to iCloud.  I would like a reduced contact list on my iPhone without removing any from my master list on my computer.  How do I delete contact numbers from my iphone without disrupting the master list on my computer?

    Are you trying to reduce the visual clutter on the phone, save space on the phone, or limit the security exposure if your phone is stolen?
    If you are only wanting to reduce the visual clutter and make scrolling through the list faster, you could set up a group on the computer containing only the contacts you want to see on my phone (called, for example, "Show on my Phone") and enable only that group inside Contacts on the phone. You might even have one or more existing groups that you could enable that way (maybe "Family" and "Personal").

  • How to display the search result without reloading the whole page

    HI,
    I have separate fragments for Search Box to enter keyword and Search Result to display the result. Also I have different sections within the page to put these fragments. So how could I display the results without reloading the whole page.
    Also if I have next button in my search result area, how could I display the search results in next page without reloading all other sections present in our page. Please let me know if any service or idoc function present such that result could be shown in search result section without reloading whole page.
    Please let me know how to restrict page reload for every action within a page.
    Thanks,
    Ramesh
    Edited by: Ramesh_Est on May 27, 2010 3:14 AM
    Edited by: Ramesh_Est on May 27, 2010 8:39 PM

    This is default behaviour of the template of your space. You can create a new page template and than you can create a region for the search results.
    Or you can create a custom taskflow were you use the webcenter taskflows to search for the space.
    Take a look at this white paper:
    Extending webcenter spaces: http://www.oracle.com/technology/products/webcenter/pdf/owcs_r11_extend_spaces_wp.pdf
    and this one:
    Customizing site templates: http://www.oracle.com/technology/products/webcenter/pdf/owcs_ps1_site_template_wp.pdf
    Edited by: Yannick.O on 13-Apr-2010 02:32

  • How can I protect formulae in a newly created spreadsheet without locking the whole sheet ?

    How can I protect formulae from being overwritten on a newly created spreadsheet without locking the whole sheet ?

    Olly,
    I'll be picky here on nomenclature ;-)
    Tables and other Obects can be locked, but Sheets can't be locked.
    If you wish to shield some parts of your content from accidental modification, arrange your layout to put that sensitive content in tables separate from the tables that need to be accessed, and lock the sensitive ones. It's also possible, but rather clunky, to place shields over the sensitive area. A shield can be made by Inserting a Shape and positioning the shape over the sensitive area. With the shape selected, go to the Graphics Inpector and set the Opacity of the shape to zero. You will then be able to see through the shape but will no be able to Click through it to get at the cells below. This method is inconvenient because you have to worry about keeping the shape aligned with the table should the table need to change size or shape.
    Jerry

  • Can i listen to the music on my cloud without downloading the music files to my computer?

    Can I listen to music via the cloud without downloading the actual files to the device?
    Basically I want to listen to my music at work without putting the files on my work p.c.
    thanks

    This is not possible. Your purchased music must be downloaded to your computer to listen to the full song.

  • I tried to delete one item from an email folder, and my computer deleted the whole file. I cant fint it anywhere.

    I tried to delete one item from an email folder, my computer deleted the whole file and I cant find it anywhere. Any ideas?

    lindafromgainesville wrote:
    ...is there a seperate trash for email?
    In Mail, yes -

  • Is there a way to access my iTunes Library, which is stored on a (PC) External Hard Drive, on a MacBook Air (through an Apricorn Universal Hard Drive Adapter), without transferring the music files off of the external hard drive?

    Is there a way to access my iTunes Library, which is stored on a (PC) External Hard Drive, on a MacBook Air (through an Apricorn Universal Hard Drive Adapter), without transferring the music files off of the external hard drive?
    In other words, because the MacBook Air only has 120 gbs of hard drive space & my old hard drive, from a Lenovo, has 500 gbs of hard drive space (and I have over 120 gbs of music), I’m looking to manage my iTunes music from the external hard drive permanently. Upon attempting to access the iTunes library held on the external hard drive the following message comes up: “The iTunes Library.itl file is locked, on a locked disk, or you do not have write permission for this file”.  Is there a way to get around this?
    Any advice would be greatly appreciated, thanks so much!

    You will have to engage a split library which means you will have to start answering questions on this forum because you will need to learn a lot about how iTunes works in order not that have a big mess at the end of it all.  It also won't be easy when the time comes to relocate it all to different drives.
    You can go to advanced preferences and turn off organize media and copy to items to media folder when adding items to library.  Next read about how to selectively consolidate items to the external drive.
    Sept. 2010, Consolidate selected content - https://discussions.apple.com/thread/2589812 and April 2014, https://discussions.apple.com/message/25414357
    "...selected the new tracks directly in iTunes, Control-clicked on the selection, and saw that now you can consolidate selected items." - http://hints.macworld.com/article.php?story=20090919000326840
    Remember that when you start iTunes without the external drive turned on iTunes will present you with a bunch of broken links.  If you have automatic downloads enabled with iCloud you may have to turn that off to prevent iTunes from repopulating your drive trying to deal with those "missing" tracks.
    If you add tracks in bunches to iTunes and want them to go to different media folders you will need to either add them by holding down the option key while dragging if the desired media folder is not the one set in preferences, or by changing the media folder in preferences.  Changing media folder preferences only applies to new files added, not old ones.
    Okay, I am going to stop typing because you might just reply to me, "Oh, okay, forget it," and I don't need the exercise.
    What are the iTunes library files? - http://support.apple.com/kb/HT1660
    More on iTunes library files and what they do - http://en.wikipedia.org/wiki/ITunes#Media_management
    What are all those iTunes files? - http://www.macworld.com/article/139974/2009/04/itunes_files.html
    Where are my iTunes files located? - http://support.apple.com/kb/ht1391

  • How do you get your music on your phone without syncing the whole iTunes library on your phone?

    How do you get your music on your phone without syncing the whole iTunes library on your phone?

    Are you syncing to a different computer?  Iphone will sycn with only one at a time.  Syncing to another will erase the current content.
    Otherwise, just select what you want to be on the iphone under the music tab and sync.  What do you care if it erases?  You will be syncing what you want to the iphone.

  • How to disconnect internet connection in Time Capsule and reconnect without restarting the whole device?

    Hi, I would be very grateful if someone could tell me how to disconnect internet connection in Time Capsule and reconnect without restarting the whole device?
    The thing is that as I have a dynamic IP address, everytime I restart the internet connection my IP address changes. I sometimes need it to change, so I need to restart the connection. I don't know another way to restart the connection than restarting the whole Time Capsule.
    Thanks!!
    PD: the computer I use is Windows based, using the Airport Utility for Windows, but I also have a MacBook Pro I could use and an iPhone too.

    The utility in windows is very like Mac so the screenshots are from Mac as I don't have windows available now.
    How this works depends on the setup of the TC.. which you did not tell us.. you cannot change anything if you do not have the TC as the main router in the network.
    So on the internet tab you need to share a public IP address.
    On the next tab where you set IP address.
    Click the renew IP address.
    It might work.. and it might not.. the problem is you are not disconnecting the network.. sometimes the hard disconnection is required before the address will renew..
    What about unplugging the WAN port.. then click renew the IP which will fail.. then plug the wan back in again.
    In the end it is easier and faster to power cycle the TC.

  • I've updated all my software and iTunes on my Macbook Pro but when I went to open iTunes it tells me it's either corrupted or not installed correctly and to reinstall it. Is there anyway to fix it without reinstalling the whole program?

    I've updated all my software and Itunes on my Macbook Pro but when I went to open iTunes it tells me it's either corrupted or not installed correctly and to reinstall it. Is there anyway to fix it without reinstalling the whole program?

    Here's a previous discussions that seems to have solved a similar issue in the past:
    https://discussions.apple.com/message/12209861#12209861

  • How to AVDocGetPDDoc without opening the pdf file

    Hi all,
    how to AVDocGetPDDoc without opening the pdf file in acrobat plugin sdk.
    Regards,
    JK

    thanks for ur reply, now its fine.

  • How to change the width for adf shuttle without modify the skin file

    Dear Professionals
    I haven an ADF Shuttle component in my jsp screen , How can i change the width for the two boxes without modify the skin files.(I know i can do that by skin but what i want to change one shuttle just in one screen not change all shuttles on other screens).
    Regards
    Wish79

    Okay, I didnt try with the trinidad selectmanyshuttle, but this worked for me on the af:selectmanyshuttle..
            <af:selectManyShuttle label="Label 1" styleClass="mycustcss">
              <af:selectItem label="Label1" value="value1"/>
              <af:selectItem label="Label2" value="value2"/>
            </af:selectManyShuttle>
            <af:selectManyShuttle label="Label 1">
              <af:selectItem label="Label1" value="value1"/>
              <af:selectItem label="Label2" value="value2"/>
            </af:selectManyShuttle>        And in my css file, I have
    af|selectManyShuttle.mycustcss::content { width: 800.0px;}
    The first selectManyShuttle came up very wide and the second one came up in the default width..
    Julian.

  • How do i delete files in pages, i have some old invoices in pages that i want to delete, i can delete the text but not the whole file, please help. Dennis

    As it say's above i need to delete some of my oldinvoices/estimates from my files in pages, i can get rid of the text but not the whole file, thanks Dennis

    You locate the file in the Finder(it's in the Documents item of the sidebar by default), drag it to the Trash, and empty the Trash.
    (59926)

Maybe you are looking for

  • Can I connect a 4 TB USB drive to the airport extreme and use it as a network drive for Time Machine

    Can I connect a 4 TB USB drive to the airport extreme and use it as a network drive for Time Machine

  • Can't print from Mac to Windows printer

    I have a wireless network of 3 computers and a printer. One is a desktop running XP with the printer attached. The other is a laptop with XP. And the last is a MacBook with 10.4.11. I can print from both computers running XP but I can't print from th

  • How to edit the T9 word suggestion list

    HI all, I hope someone can help here..  I'm using the N97 with original firmware (no update available yet). When I'm using T9 text input from the dialpad and type 86 which should give 'to' I get 'vo' instead which is not even a word as far as I know,

  • Change of Standard Currency Translation Logic

    Hello everybody, I need to achieve special goal to for a user request: In a BPC planning application using version 5 MS I would like to import data from another data source and perform a currency translation from LC to RC. The application is NOT set-

  • Cannot view attachments

    I cannot view attachments sent thru an email nor can I view anything sent from store advertisements. When the Gap sends me an email and I open the email I cannot view the pictures or advertisement's. The picture looks like it would if it were sent to