Appending new TextLine into existing file

I tried to add new text lines into an existing txt file. The problem is my method add new Strings on the same line (to see it you need to open the output file with notepad).
The method invoked is:
public static void addText( String arg0, String path ) {
          long pos;          
          try {
               raf = new RandomAccessFile( path , "rw" );
               pos = raf.length();
               raf.seek( pos ); //mi sposto alla fine del file
               raf.writeBytes( "\n" ); // new line
               raf.writeBytes(arg0); //
               raf.close();
          } catch (FileNotFoundException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
     }

To make your app system-independent use:
  String lineSeparator = System.getProperty("line.separator");as line separator
[]

Similar Messages

  • How I can append new node in existing  XML file

    I've just begun learning DOM XML , so I'm currently at a very beginner level.
    I have an existing XML file that I would like to add an additional node to before saving it to another variable.
    how I can append new node in this file.
    now this code is overwrite new data over old data
    The code looks like this:
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.transform.Result;
    import javax.xml.transform.Source;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.TransformerFactoryConfigurationError;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Attr;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    public class VerbXMLWriter
        static String EVerb3;
        static String englishTranslate3;
        public void VerbXMLWriter(String EVerb, String englishTranslate )
             EVerb3 = EVerb;
             englishTranslate3=englishTranslate;
        File xmlFile = new File("VerbDB.xml");
        DocumentBuilderFactory factory =  DocumentBuilderFactory.newInstance();
        try
         DocumentBuilder builder = factory.newDocumentBuilder();
         Document document = builder.newDocument();
        Element root = document.createElement("Verb");
         document.appendChild(root);
         Element verb = document.createElement(EVerb3);
         verb.setAttribute("EnglishTranslate",englishTranslate3);
         root.appendChild(verb);
         Source xmlSource = new DOMSource( document );
         Result result = new StreamResult( new FileOutputStream(xmlFile) );
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer =
        transformerFactory.newTransformer();
        transformer.setOutputProperty( "indent", "yes" );
         transformer.transform( xmlSource, result );
      catch(TransformerFactoryConfigurationError factoryError )
        factoryError.printStackTrace();
       catch (ParserConfigurationException pc)
           pc.printStackTrace();
       catch (IOException io)
          io.printStackTrace();
       catch(Exception excep )
           excep.printStackTrace();
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <Verb>
    <Play EnglishTranslate="playing" />
    </Verb>Edited by: itb402 on Mar 9, 2008 6:05 AM

    in your code you are already appending new nodes to the root node. so what exactly is your problem? The following steps are usually taken for appending a new node:
    1. Read the XML document
    2. Build a DOM tree
    3. Navigate to the node under which you want to insert the new node
    4. Create a new node.
    5. Insert the new node to the node selected in point #3.
    ~Debopam

  • How to uncheck "Add as a new version to existing files" inside the "Add a document" dialog

    I am working on a publishing site collection using the enterprise wiki template. Currently when users want to insert an image inside the rich text editor, they will be prompted with the following:-
    And if the user insert a picture that already exists then it will replace the existing one, which might cause the picture to be displayed inside a Wiki page which it does not belong to !!
    So is there a way to do any of the following:-
    Give the new picture a unique auto generated name?
    To un-check the   “Add as a new version to existing files” by default?
    Or to always prevent replacing images, as this can cause many conflicts !!
    Can anyone advice ?please?

    You can do it using below script
    http://webcache.googleusercontent.com/search?q=cache:51tmEQHanZoJ:vegardstromsoy.blogspot.com/2011/05/jquery-to-override-sharepoint-ootb.html+&cd=4&hl=en&ct=clnk&gl=in
    $(document).ready(function() {
        if (document.title ==
    "Upload Document") {
            $("input[id$='OverwriteSingle']").attr("checked",false);
            $("input[id$='OverwriteMultiple']").attr("checked",false);
    http://hansiandy.wordpress.com/2010/10/19/sharepoint-20072010-tips-uncheck-add-as-a-new-version-to-existing-files-checkbox-on-upload-aspx-in-moss-2007sharepoint-2010/
    If this helped you resolve your issue, please mark it Answered
    but where i should add the following jQuery :-
    $(document).ready(function() {
    if (document.title == "Upload Document") {
    $("input[id$='OverwriteSingle']").attr("checked",false);
    $("input[id$='OverwriteMultiple']").attr("checked",false);
    inside the master page or insdie the upload.aspx page ?

  • Print a new model into a file

    Hi everybody!
    After capturing a design from a server model,
    what can I use to print the new model into a file ??
    Thanks for any help!

    RMy wrote:
    > I prefer to make a screen dump (Alt+PrintScrn) and paste picture into
    > my document. Alternative: Print to a .rtf-file. Problem is with large
    > blockdiagrams that doesnt fit into one page. Solutions?
    Maybe installing a hpgl-driver and print to a file.
    Download the hpgl-graphics filter from microsoft (was included until
    Office 95 i think) and import it to the word-document.
    You'll lose the colors this way (as far as i remember).
    Use a postscript printerdriver to print to a file. Convert it to
    something, you can import to your application.
    Use a pdf-printerdriver. But I don't know how you can import graphics
    from pdf (a subset of postscript) to other applications.
    Print to PostScript-File, use ImageMagick's "convert" program to conver
    t
    it to something userful for you and import it.
    These are my ideas...
    bye
    Marco

  • Acrobat 9 Std-how to append new pages to existed/opened pdf file

    i am using Acrobat 9 standard version.
    when i used the scanner to create a pdf, but the file had many pages so i could not finish it before lunch. Therefore, i had to append new pages to the opened file.
    In past, 7 standard i could choose append to the opened file but 9 standard i don't have this function. Finally, i found the
    DOCUMENT / SCAN TO PDF / CUSTOM SCAN / TICK THE APPEND TO .....
    But, only 1 scan is allowed , what can i do now ????

    You can scan to different files, the you should be able to insert the
    second group of files into the first file using Documtent->Insert Pages.
    Mike

  • LabVIEW created .DAT file with saving only new data on existing files

    I can successfully create and save a .DAT file using LabView and Diadem.   The save command I am using (in Labview) only overwrites existing files, I would like it to save only the new data from the last save.  Overall I would like to save the data every 1hr and since my test will last for many hours, the further along in the test the longer it would take to save the full file.  I know Diadem has the capability to save in such a manner, so I have thought about after I write to Diadem have a small Diadem application save periodically, but I haven't found a way to save the .DAT file, with out any signals coming into the save function.  I have attached the example .DAT file creater and saver I am using to figure it out.  thanks for your help!

    Howdy New Guy -
    I am not sure if you are looking to append to a file, or if you would
    like to overwrite a file.  In either case, you can take a look at
    the "Append To File.vi" example for DIAdem. 
    Either way, you may be experiencing problems because you are only using
    the "DIAdem Simple File Write.vi" (found on the DIAdem >> DAT
    Files palette).  Instead, you can use the "DIAdem File Write.vi"
    (located on teh DIAdem >> DAT Files >> DAT Files Advanced
    palette).  This VI can be set to overwrite or append to file.
    I hope this helps in your development!
    Andrew W. || Applications Engineer

  • How to append contents to an existing file contents at the end of file?

    Hi all
    I am Kiran, working with LV8.0  FDS
    I find difficulty while trying to add new file contents(some messages)  to an existing file at the end /begining of a file.
    Whenever i try to do that,it is replacing the previous contents,but i dont need that. i want the contents to be appended.
    Plz suggest me.
    thanks & regards
           kiran

    Hi Kiran,
    yes, I can attach a screenshot
    (open file, set file position to end, write text, close file)
    Message Edited by GerdW on 08-16-2007 03:19 PM
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    append.png ‏2 KB

  • Write into existing file with "write to text file"

    Hi all,
     I have a text file that contains several lines of data (text). Now I would like to replace the first three lines with text coming from a string array.
    My approach is shown in WriteToFile.vi that is attached.
    When I am executing this vi (with an empty file), everything seems to be working fine in the first place.
    The file will contain the following text:
    oneoneone
    twotwotwo
    threethreethree
    Now, when the third element in the array is shortened (lets say to "threethr") before execution,  the file will contain  the following text:
    (the file was not emptied before execution)
    oneoneone
    twotwotwo
    threethr
    three
    How can I avoid the last line being written? I have made many tests and I could not find a solution.
    One more example:
    Lets say we have an existing file, inside this file is:
    oneoneone
    twotwotwo
    three
    fourfourfour
    Now I would like to overwrite line three with "threethreethree". Therefore I execute my vi as shown in the attachment.
    What I get as a result is:
    oneoneone
    twotwotwo
    threethreethree
    ur
    So, the text in line four, which should not be touched, is "ur" instead of "fourfourfour".
    Any idea to solve this problem?
    What I basically need is replacing a line of a text file in a conveinient way.
    Thanks,
    Holger
    LV 8.5.1
    Attachments:
    WriteToFile1.jpg ‏17 KB
    WriteToFile.vi ‏11 KB

    The remaining fourth line is there because the third line has a <nl> at the end. You have not emptied the file so the rest of the file will be kept. This is because your line is shorter.
    In the scond example the third line is longer and it will overwrite the beginning of the fourth line.
    Files aren't organized in lines they are oganized in bytes. And what you write are bytes to the file even with text files.
    Replacing a single line in a file is done by reading the file line by line. All unchanged lines are written to a temporary file and the line with the new text will be written instead of the original line to the temporary file. When the writting is done rename the original file, then rename the new file into the original file and then delete the renamed original file.
    Waldemar
    Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
    Don't forget to give Kudos to good answers and/or questions

  • How to Load new members into existing dimensions in Planning 9.3.1

    Hi,
    I am not having HAL, and is it possible to load members into existing dimensions of a newly created planning application - for example under accounts I want to add around 100 members - how to add them using a flat file without using HAL - is there anyother way out.
    Can we use workspace->Navigate ->administer->Dimention Library
    Create a new dimension here add that to Accounts ?? help me in this

    John,
    Can you suggest me the syntax to be used for the below example to create a flat file
    the Hiearchy I have(for accounts and entity)
    current:
    Accounts
    I need t have the following children under Accounts
    Child of Accounts:Assets,alias(assets of x company)
    Child of Asssets: 101, alias(asset1),Datastorage("store"), base currency("USD"),aggregation(+),Plantype("plan1")
    Regards,

  • Append stream object to existing file

    Hello, I'm trying to append a live stream to an existing file, but I cant figure out how to open the existing file and then append the live stream. This is server side as well.
    I know I need to open the existing file using stream = stream.get("file"). but I don't understand how to associate stream with the live stream coming in.
    PLEASE HELP~!!!

    This is what I have now, and it still overwrites :*(
    application.onPublish = function (p_c, p_stream)
        //check for the file helpers   
        filePath = new File("/streams/_definst_/");                             
        fileName = p_stream.name + ".flv";
        fileTest = filePath.fileName;     
        if (fileTest.exists == false){
            p_stream.record();
        } else {                
            mynewstream = Stream.get(p_stream.name); 
            mynewstream.onStatus = function(info){
                 trace(info.code);
            mynewstream.record("append"); 
            mynewstream.play(p_stream.name ,-1,-1,true);   //where livestream in name of stream getting published.

  • How do you move new photos into existing albums?

    On an iPad how do you move a new photo into an existing album?

    Or, from the camera roll:
    Tap Select (upper right hand corner)
    Tap the pictures you want to add to an album (you'll see a check mark in each selected photo)
    Tap Add To (upper left hand corner)
    Your albums will appear and touch the album you want to move the picture to and they'll go there
    Note:  They will stay in your Camera Roll as well

  • Can not add new VMS into existing clustered server pool

    For some reason, we reinstall VMM (3.1.1-416) with existing UUID and rediscover all VMSs. The process went smooth and the whole system looks clean without dead objects any more. The guest VMs are all working fine. However, the new added VMS in unassigned servers are not displayed in the "Available Servers" when we want to add into existing clustered server pool, but it is shown when we add into unclustered server pool. Anyone has clue or possible way to debug what's wrong.
    Thanks,
    Shun-Jee Liu

    The issue is resolved. The access group in shared iSCSI is not properly configured.

  • CUKD_API_DEP_MAINTAIN  -  Append new rows in existing Dependency

    Hello,
    I would like to know if ther's any way to append new rows within an existing dependency
    without having to reload all pre-existing rows.
    I'm already using function CUKD_API_DEP_MAINTAIN but I haven't found the way to
    append only new rows.
    This problem is due to the fact that my dependencies are reaching more than 9.999 rows
    and the dependency index used by the function ( DEPSOURCE-LINE_NO ) is a NUMC 4 
    Does anyone know if there is a different function I can use or how to work it around
    function CUKD_API_DEP_MAINTAIN?

    Hello Pradeep,
    Could you tell me why we are passing parameter FL_SYNCH to blank  ? I got similar issue.
    Many Thanks,
    Jitendra

  • Append data to a existing file thru ALSB Service

    Hi,
    I want to write/append message data to a file before and after I invoke a Business Service.
    I have created a Business Service with Service Type as Messaging Service and the protocol as FILE. I notice that everytime I call the Business Services a new text file is created. Is there a way I can append messages to the same file.
    The workaround I thought of is to write a Java Class to write/append data to a file and invoke this as a Java Callout. Is this a feasible/good solution.
    If anybody has any ideas of implementing this, please help.
    Thank you.

    This feature is not supported by ALSB
    You are correct, your best bet is to write some code in a Java callout to implement your expected behavior.
    Gregory Haardt
    ALSB Prg. Manager
    [email protected]

  • Add new city into existing Network metadata

    i have one network data model in my database for delhi city i am using Oracle 10 g spatial. how to add one more city into existing network metadata?

    If the column structure is different, how did you load the Delhi data into NDM tables ?
    You have to load the shape file first and then do the required mapping to move that into the NDM tables.
    Secondly, are you using the PL/SQL api to do the network analysis ? Or are you using the Java api ?
    siva

Maybe you are looking for