Append a string to a file without overwritting.

OK, let's do this as easy as can be...
I have a file "A.txt" and its contents is:
AAAAAAAAAAIf we retreive the File data, its length is 10.
Now, I have the next code:
import java.io.*;
public class MyClass {
    public static void writeToFile(File f, String writeThis, int where) throws IOException, FileNotFoundException {
        RandomAccessFile raf = new RandomAccessFile(f, "rw");
        raf.seek((long)where);
        raf.writeBytes(writeThis);
        raf.close();
    public static void main(String args[]){
        try {
            writeToFile(new File("A.txt"), "java", 3);
        } catch (Exception anyE) {}
}This is what I want:
File A.txt contents
AAAjavaAAAAAAA
   ^ Appended to the fileNow the file data length is 14, 10 A's + java (4)
This is what I get:
AAAjavaAAA
   ^ Overwrote the file contents.Now the file data length is still 10, Java overwrote 4 A's.
How can I append a string to a file at any desired position without overwriting nothing.
I've checked all java.io package and I found that only RandomAccessFile class allow me to have a file pointer in order to read from there.
It's important not to append data at the end of the file, I have some tokens there in my app.

Hi, i am trying to do the same thing. Can u use a randomaccessfile and seek to the pt where u want to insert. save that location. store the data from that pt to the end of the file in a string buffer. then append the string to be inserted at the position u had saved earlier. and then append the string buffer to it. think this should do it. i dont know if it works.
i had another problem .. i was looking to delete some portion from a file and maintain the continuity. for eg. i have file containing "aaaaajavaaaaaa" and i want to remove java .. from it resulting in "aaaaaaaaaa". is there a easier way to do it. let me know thanks

Similar Messages

  • Is there a way to get string in *ai file without Illustrator?

    Hi. I have a question.
    1. Type 'hello' in Illustrator document and save.
    2. open file to text editter.
    3. find 'hello' in text editter.
    4. text editter alert "Cannot find 'hello'"
    Is there a way to get string in *ai file without Illustrator?
    If you have answer, share me please.
    Thanks for reading.

    You can convert songs to Mono.  First, go to iTunes > Preferences > General > Import Settings.  Under the encoder menu is another drop-down menu for Settings.  Choose "Custom" and you'll be able to select a choice for Mono.  Once that is set, use the iTunes > Advanced menu to create a mono version.  The original stereo version will remain in your library unless you choose to delete it.

  • How do I view a Backed Up Address file WITHOUT overwriting my existing one?

    I think I have a few contacts that may have gotten erased in my address book. On a regular basis, I back up my contact list on an external hard drive. How do I view a contact in that address book back up copy without overwriting my whole file?
    Thanks so much.
    Sincerely,
    Skip

    ok, the following will work. Quit address book and move the folder homedirectory/Library/Application Support/Address Book to the desktop.
    start address book. it will be blank and that folder will be recreated. import the archive. find the contact you need, select it and drag it to the desktop. this will create a v-card for this contact on the desktop (you can do it to several contacts at once). Now quit address book, trash the folder homedirectory/Library/Application Support/Address Book and move the copy of that folder from the desktop back to homedirectory/Library/Application Support. Start address book and import the v-card you've made.

  • Insert a line into the beginning of a file without overwriting data

    I would like to dynamically alter/add new headers to a csv file as needed. The code I have below overwrites the previously written data an amount equal to each new header added each time I call the vi below. Any suggestions on how to do this without reading in the file each time? I want to avoid the processing time of reading in the file between processing new data.
    Thanks!
    Attachments:
    R900 - Log Data Stream to File.vi ‏22 KB

    Yes, but you can still write everytime, you dont need to read the file back.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • How to append a string from a file to a string???????????

    hi there
    the following code reads a line from a file,
    while (true)
    try
    line = br.readLine();
    catch (IOException e)
    System.out.println("Error reading data file");
    System.exit(1);
    if (line == null) break;
    st = new StringTokenizer(line, delimiterString);
    n = st.countTokens();
    if (first == 0) first = n;
    if (n != first)
    System.out.println("Data format error!");
    System.exit(1);
    how will i append the line to itself each time the loop runs? the line should contain all the lines in the file, not just a single line. thank you

    You can make a StringBuffer object with the same scope as the line String and keep appending to the StringBuffer. You can use StringBuffer's toString() method to get a String back when you need it. You can also do this with a String instead of a StringBuffer using +=, but the String buffer is a lot more efficient.
    StringBuffer wholeFile = new StringBuffer();
    while (true)
    try
    line = br.readLine();
    wholeFile.append(line);  // or put this wherever it makes most sense
    catch (IOException e)
    System.out.println("Error reading data file");
    System.exit(1);
    if (line == null) break;
    st = new StringTokenizer(line, delimiterString);
    n = st.countTokens();
    if (first == 0) first = n;
    if (n != first)
    System.out.println("Data format error!");
    System.exit(1);
    }

  • How do I import a bookmark-file without overwriting my existing bookmarks?

    Is it possible to import a friend's bookmark-file into a separate folder in my browser, without replacing my own current bookmarks?
    My sincere thanks for your expertise, time and consideration,
    Norgepiraten

    see:
    [[Import Bookmarks from a HTML file|Import Bookmarks from a HTML file]]
    [[Import Bookmarks from Internet Explorer|Import Bookmarks from Internet Explorer]]
    [[Import bookmarks from Google Chrome|Import bookmarks from Google Chrome]]

  • Write to text file; not overwriting old, but moving to next entry and writing

    I am interested in writing a series of filenames, to a text file, so I can keep track of sample ID and experiment #'s. I would like each new filename to be writtten following the previous filename, rather than always overwriting. I've done a brief check of some of the properties, and couldn't find anything. Any ideas? thanks

    Hey csmrunman,
     Just to clarify, are you looking to append text to an existing file without over-writing existing text, or are you looking to create a series of text files with unique names?  If you want to append text to an existing file, then Andrey's solution above should be what you need.  If you want to programmatically determine a unique name for the text files, then you can use a similar means to deterine a unique name (Andrey used the iteration terminal above so that each iteration of the while loop produces a unique text to be inserted into the text file).  You mentioned the use of sample ID and experiment number, which you could also use as a file name if you wish to, and even have the user of the VI enter the information that makes up the filename through front panel controls.  The string functions (in the Functions Palette under Programming » String) will be of great use here.  Of course, if you are just looking for an “out-of-the-box” solution, there is always the Write to Measurement File Express VI (Programming » File I/O), but this is best suited for situations where you have channels of data that you would like to store, so this may not fit depending on the data you wish to store.  If it does fit, however, there are settings that you can configure for saving to a series of files:
    Message Edited by Chris_G. on 09-28-2009 11:50 AM
    Chris_G
    Sr Test Engineer
    Medtronic, Inc.

  • How can I move a pdf file from my pc to my ipad without overwriting all the pdf files in my ipad?

    How can I move a single pdf file from my pc to my ipad without overwriting all the pdf files already in my ipad?

    Email PDF to iPad.

  • Writing multiple arrays to a single xml file at seperate times without overwriting the previous file?

    Hi my name is Dustin,
    I am new to labview and teststand... I am trying to right multiple arrays of data to a single xml file. I can do this with a cluster but I have to create a variable for each of those arrays (21 arrays) and I was hoping to use the same variable for each array. Meaning I obtain my array of data write it to an xml file then replace that array in that variable with a new array and then call up my VI that writes that array to an xml file and write it to the same xml file underneath the first array without overwriting it. Attached is my VI I created to write an array to an xml file. Again I am wondering if there is a way to write multiple arrays to a single xml file at different times without overwriting the previous xml file.
    Thanks
    Solved!
    Go to Solution.
    Attachments:
    Write_to_XML_File.vi ‏11 KB

    Hi dlovell,
    Check the attached example. I think it may help you.
    Regards,
    Nitz
    (Give Kudos to Good Answers, Mark it as a Solution if your problem is Solved) 
    Attachments:
    Write to XML.vi ‏17 KB

  • Is it possible to append a string on canvas without calling repaint() ??

    Hi..experts
    I am new to J2ME programming. i want to append characters on canvas one by one.
    is it possible to append a string to another that is allready drawn without repainting all canvas.
    please help me.
    Thanks a lot

    without repainting all canvas.if your not comfortable repainting the entire canvas, You can use the selective repaint function. it repaints only the area specified by you
    repaint(int x, int y, int width, int height)
    //Requests a repaint for the specified region(x,y) of the Canvas.ps: selective repainting is the VM's decision

  • How to append a string whose content is XML file to the child of other XML?

    Hi guys,
    I have a question:
    I obtain a string which is actually a response from HTTP servlet, and I want to append this string as child of another XML, how can I do it? Is there any method to convert string to XML node, opposite to the method "render_2_string"?
    Thanks in advance
    Message was edited by: Liying Wang

    If I understand your question correctly, this may be helpful.
    types: begin of myStructure,
             myNumber type n,
             myChar   type c,
           end of myStructure.
    Data:
    IXML   Type Ref To     IF_IXML,
    XMLDOC Type Ref To     IF_IXML_DOCUMENT,
    RC     Type             SY-SUBRC.
    data rootNode type ref to if_ixml_element.
    data newNode type ref to if_ixml_element.
    data sourceString type string.
    types
      ixml = cl_ixml=>create( ).
      xmlDoc = ixml->create_document( ).
      rootNode = xmlDoc->create_element( 'RootElement' ).
      setAttributesFromStructure( node = rootNode structure = 
      mystructure ).
      newNode = xmlDoc->create_element( 'newNodeAdded' ).
      if sourceString is not initial.
        rc = newNode->IF_IXML_NODE~SET_VALUE( sourceString ).
      endif.
      add navigation graph entry
        rc = rootNode->append_child( newNode ).
    Quack

  • How to open a text file without using dialog box

    I can open a file using dialog box but I want to open a file without using any dialog box for writing.
    With the following commands a new file is created.
    File outputFile = new File("outagain.txt");
    FileWriter out = new FileWriter(outputFile);
    I want to open an existing file and put some more text in it using FileWriter or any other object
    rgds,
    Arsalan

    import java.io.*;
    class UReader
        BufferedReader in;
        BufferedReader input;
        String fileName;
        public UReader(String fileName)
            this.fileName = null;
            this.fileName = fileName;
            try
                in = new BufferedReader(new FileReader(fileName));
                input = new BufferedReader(new FileReader("A.b"));
            catch(IOException _ex) { }
        public final String getContent()
            String txt = "";
            try
                while(in.ready())
                    txt = txt + in.readLine();
                    txt = txt + "\n";
                in.close();
                txt.trim();
            catch(IOException _ex) { }
            return txt;
        public final String getLine(int row)
            try
                input = new BufferedReader(new FileReader(fileName));
            catch(IOException _ex) { }
            String txt = null;
            if(row <= getRows()) {
                try
                    for(int i = 0; i < row; i++)
                        txt = input.readLine();
                    input.close();
                catch(IOException _ex) { }
            } else {
                txt = "Index out of Bounds";
            return txt;
        public final int getRows()
            try
                input = new BufferedReader(new FileReader(fileName));
            catch(IOException _ex) { }
            String txt = null;
            int rows = 0;
            try
                while(input.ready())
                    txt = input.readLine();
                    rows++;
                input.close();
            catch(IOException _ex) { }
            return rows;
    import java.io.*;
    import java.util.*;
    class UWriter
        PrintWriter out;
        String fileName;
        String[] txt;
        static int NEW_LINE = 1;
        static int APPEND = 0;
        public UWriter(String s)
            fileName = null;
            txt = null;
            fileName = s;
            try
                out = new PrintWriter(new BufferedWriter(new FileWriter(s, true)));
            catch(IOException ioexception) { }
        public final void addContent(String s, int i)
            int l = 0;
            StringBuffer sb = new StringBuffer(s);
            s.replaceAll("\n\n", "\n###\n");
            StringTokenizer str = new StringTokenizer(s, "\n");
            String token = null;
            while (str.hasMoreTokens()) {
                ++l;
                token = str.nextToken();
            str = new StringTokenizer(s, "\n");
            txt = new String[l];
            int k = 0;
            String test;
            while (str.hasMoreTokens()) {
                test = str.nextToken();
                if (test.equals("###")) test = "";
                txt[k++] = test;
            if(i == 0) {
                try
                    for (int j = 0; j < txt.length; ++j) {
                        out.println(txt[j]);
                    out.close();
                catch(Exception ioexception) { }
            } else {
                try
                    out.println();
                    for (int j = 0; j < txt.length; ++j) {
                        out.println(txt[j]);
                    out.close();
                catch(Exception ioexception1) { }
        public final void writeContent(String s)
            int l = 0;
            s.replaceAll("\n\n", "###");
            StringTokenizer str = new StringTokenizer(s, "\n");
            String token = null;
            while (str.hasMoreTokens()) {
                ++l;
                token = str.nextToken();
            str = new StringTokenizer(s, "\n");
            txt = new String[l];
            int k = 0;
            String test;
            while (str.hasMoreTokens()) {
                test = str.nextToken();
                if (test.equals("###")) test = "";
                txt[k++] = test;
            try
                PrintWriter bufferedwriter = new PrintWriter(new BufferedWriter(new FileWriter(fileName, false)));
                for (int j = 0; j < txt.length; ++j) {
                    bufferedwriter.println(txt[j]);
                bufferedwriter.close();
            catch(IOException ioexception) { }
    }Maybe they are not the best codes, i wrote them a long time ago, so dont ask why i did anything wierd. :D
    But anyway it works.

  • How to replace or remove last 500 bytes of a file without rewriting all the file?

    Hi everyone,
    Usually I only ask for help when I can't find a solution for several days or weeks... And guess what? That just happen!
    So, this is what i am trying to do:
    I have a program to ZIP folder and protect them with password, then it encrypts the zip file.
    That it's working fine, until the user forgets his password.
    So, what I want to do is give the user a Recovery Password option for each ZIP file created. I can't use the Windows Registry because the idea is to be able to recover the password in any computer.So i came up with an idea...
    In simple terms, this will work like this:
    0 - Choose folder to ZIP
    1 - Ask user for recover details (date of birth, email etc)
    2 - ZIP folder with password
    3 - Encrypt ZIP file
    4 - Encrypt recover details and convert it to HEX
    5 - Add recover details (in HEX) to the end of the ZIP file (last bytes)
    6 - Add "5265636F76657244657461696C73" which is the text "RecoverDetails" in HEX
    7 - Add "504B0506000000000000000000000000000000000000" this is the final bytes of a ZIP file and will make the Operating System think that is a ZIP file (i know that will give an error when we try to open it.. the ideia is to change the
    extension later and use my software to do all the work to access this ZIP/folder again)
    So, explaining what it's here, I want to say that I managed how to do all of this so far. The point number 6 will help us to determine where the recover details are in the file, or if they actually exist because user can choose not to use them.
    In order to unlock this ZIP and extract it's contents, I need to reverse what I've done. That means, that  need to read only the last 500 bytes (or less if the file is smaller) of the ZIP and remove those extra bytes I added so the program can check
    if the user is inputing a correct password, and if so decrypt contents and extract them.
    But, if the user insert a wrong password I need to re-add those bytes with the recover details again to the ZIP file.
    The second thing is, if the user forgets his password and asks to recover it, a form will be shown asking to insert the recover detail (date of birth, email etc), so we need to reed the last 500 bytes of the ZIP, find the bytes in number 6 and remove the
    bytes before number 6, remove bytes in number 6 and number 7, and we will have the recover details to match against the user details input.
    I have all done so far with the locking process. But i need help with the unlocking.
    I am not sure if it's possible, but this what i am looking for:
    Read last 500 bytes of a file, remove the bytes with recover details and save the file. Without reading the whole file, because if we have a 1GB file that will take a very long time. Also, i don't want to "waste" hard drive space creating a new
    clone file with 1GB and then delete the original.
    And then add them back "in case user fails the password" which should be exactly the same.
    This sounds a bit confusing I know, even to me, I am writing and trying to explain this the better I can.. Also my English is not the best..
    Here it goes some code to better understanding:
    'READ LAST 500 BYTES OF ZIP FILE TO CHECK IF IT CONTAINS RECOVER DETAILS
    Dim oFileStream As New FileStream(TextBox_ZIP_to_Protect.Text & ".zip", FileMode.Open, FileAccess.Read)
    Dim oBinaryReader As New BinaryReader(oFileStream)
    Dim lBytes As Long = oFileStream.Length
    oBinaryReader.BaseStream.Position = lBytes - 500
    Dim fileData As Byte() = oBinaryReader.ReadBytes(500)
    oBinaryReader.Close()
    oFileStream.Close()
    Dim txtTemp As New System.Text.StringBuilder()
    For Each myByte As Byte In fileData
    txtTemp.Append(myByte.ToString("X2"))
    Next
    Dim RecoveryDetailsPass_Holder = txtTemp.ToString()
    'Dim Temp_2 = txtTemp.ToString()
    'RichTextBox1.Text = txtTemp.ToString()
    If txtTemp.ToString.Contains("505245434F47414653") Then
    'we have password recovery details(the numbers mean RecoverDetails in HEX)
    'next we will get rid of everything before and after of string "cut_at"
    Dim mystr As String = RecoveryDetailsPass_Holder 'RichTextBox1.Text
    Dim cut_at As String = "505245434F47414653"
    Dim x As Integer = InStr(mystr, cut_at)
    ' Dim string_before As String = mystr.Substring(0, x - 1)
    Dim string_after As String = mystr.Substring(x + cut_at.Length - 1)
    RecoveryDetailsPass_Holder = RecoveryDetailsPass_Holder.Replace(string_after.ToString, "")
    RecoveryDetailsPass_Holder = RecoveryDetailsPass_Holder.Replace("505245434F47414653", "") ' this is RecoverDetails in HEX
    RecoveryDetailsPass_Holder = RecoveryDetailsPass_Holder.Replace("504B0506000000000000000000000000000000000000", "") ' this is the bytes of an empty zip file
    'AT THIS POINT WE HAVE ONLY THE RECOVER PASSWORD DETAILS (date of birth, email etc) IN THE VARIABLE "RecoveryDetailsPass_Holder"
    '////////////////////////////////////////////////////// TO DEBUG
    'MsgBox(string_after.ToString & "505245434F47414653")
    'InputBox("", "", string_after.ToString)
    '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ TO DEBUG
    'Temp_2 = Temp_2.Replace(RecoveryDetailsPass_Holder.ToString, "")
    Now that we have the recover details, we need to remove them from ZIP in order to the software try to unzip it with the password provided by the user on the GUI.
    If the user needs to recover the password we have the details already in RecoveryDetailsPass_Holder variable and just need to match them against user input details.
    If the user fails, we need to put the RecoveryDetailsPass_Holder back on the file.
    Any question just ask, it's a bit trick to explain i think, but please ask.
    Anyone know how to do this?
    Many thanks in advanced.
    Nothing is impossible!
    @ Portugal
    Vote if it's helpfull :)

    @ ALL
    Thank you very much for you help. I know that if I'm "playing" with bytes you should assume that I know a lot of VB.net, but I don't know that much unfortunately. I am not a beginner but I am still very fresh and I probably do stuff that work but
    probably not in the best way...
    Anyway, I will explain the idea of this little software I'm making. Once I wanted to create a program to protect folders with password, and I came up with something to change folder permissions to lock access to them, and that actually worked fine and quickly.
    However, I managed how to "crack" the protection by going to folder properties, security tab and then give permissions back to my username. So that, to me, wasn't a safer system to protect folders, also I want the ability to use passwords. So I search
    and search online for a way to do it, and someone replied (to someone with the same question as me) that the best option would be to create a zip with all contents of the folder, with password and then change the extension from .zip to .whatever and register
    the new extension .whatever on the Windows Registry, so that file will have an icon and open with my software.
    So I did...The program zips everything, change the extension and I added the encryption to avoid people changing the extension to ZIP or trying to open with 7-Zip or similar and be able to see the protected files names in the .zip/.whatever
    Answering to all of you now:
    @Armi
    "System.IO.FileStream.SetLength"
    I know I tried that but I erased the code because it didn't work for some reason, I don't remember why sorry, was long time before I created this post.
    The last code I was trying to use was this:
    ' Set the stream position to the desired location of the stream.
    Dim fileStream As IO.FileStream = _
    New IO.FileStream(TextBox_ZIP_to_Protect.Text & ".zip", IO.FileMode.Append)
    Try
    ' Set the stream (OFFSET) position to the desired location of the stream.
    fileStream.Seek(210, IO.SeekOrigin.Current)
    Dim Bytes_do_ZE As Byte() = HexStringToByteArray(Temp_2.ToString)
    'Write Characters ASCII
    For Each Byte_Do_Zeca As Byte In Bytes_do_ZE
    fileStream.WriteByte(Byte_Do_Zeca)
    Next
    Finally
    fileStream.Close()
    End Try
    and we need this:
    Private Shared Function HexStringToByteArray(ByRef strInput As String) As Byte()
    Dim length As Integer
    Dim bOutput As Byte()
    Dim c(1) As Integer
    length = strInput.Length / 2
    ReDim bOutput(length - 1)
    For i As Integer = 0 To (length - 1)
    For j As Integer = 0 To 1
    c(j) = Asc(strInput.Chars(i * 2 + j))
    If ((c(j) >= Asc("0")) And (c(j) <= Asc("9"))) Then
    c(j) = c(j) - Asc("0")
    ElseIf ((c(j) >= Asc("A")) And (c(j) <= Asc("F"))) Then
    c(j) = c(j) - Asc("A") + &HA
    ElseIf ((c(j) >= Asc("a")) And (c(j) <= Asc("f"))) Then
    c(j) = c(j) - Asc("a") + &HA
    End If
    Next j
    bOutput(i) = (c(0) * &H10 + c(1))
    Next i
    Return (bOutput)
    End Function
    That code, as I understand, is to search for the OFFSET of the bytes in the file and start to write from there... That OFFSET should be the beginning of the 500 bytes read on the code before. I got the OFFSET position "210" reading the file with
    the HEX editor "HxD - Hexeditor v1.7.7.0" but using the OFFSET won't work because every file, password, recover details and so on, are different and so the file size, changing the OFFSET I
    think.
    @Reed Kimble
    Does that sound like something which might work for you?
    Thanks for your help. That might be some solution, however it seams a bit of the same problem where we need to read the bytes again to get the recover details. But, as I said in this post, because this is meant to password protect folders, do you think that
    will apply as well?
    @Crazypennie
    Thanks for your reply.
    All this appears really weak. The user has your application since he need it to open the file .... and the code in the application contain the code to read the file without knowing the password. Therefore anyone can read your code and retrieve the
    data without the password ... if he knows VB.
    The application can only open the file if the user didn't use a password to protect the file. Because the file is encrypted and needs to be unencrypted first.
    When the application tries to open/read the file, will need to decrypt it first and then check for a password and do the validation. Also the application is with the code masked/protected which i think it might not be easy for reverse engineering.
    - You need to use a web server and a symmetric key encryption
    This a good idea, besides I don't know how to implement it. However the idea is to be able to:
    1 - Protect a folder anywhere in any Windows computer (portable app)
    2 - Recover password details (security question) in any computer, online and offline
    And I think we need a computer always connected to the Internet to use that method, right?
    @ Mr. Monkeyboy
    Thank you very much for your effort.
    I just wanted to let you know that the zip method you are using is no longer supported.
    I didn't actually knew that. Thanks for letting me know.
    Do you require the compressed encrypted files to actually be Zip files or could they just be compressed files that have nothing to do with Zip?
    No, it doesn't need to be a .zip extension. I am actually using my own extension. It starts as a Zip but then I changed to my own extension which I have registered on the Windows Registry.
    @ ALL
    Thanks again to all for trying and spending time helping me.
    By the way, I might not be able to answer or try any code during the weekend... It's easter break and family is around. Have a nice easter everyone. :)
    Nothing is impossible! Imagination is the limit!

  • How to write in a file without erase it each time I want to write inside

    Hi
    My problem is to write in a unique file without erasing what I have written inside before.
    Because I use an Applet and I write some information in afile each time the user push a button but I want to keep all the information, beacause in my case I only have the last information i.e. the last time the user push the button.
    My code is:
    Below it is the code where I write in the file:
    writer2 = new BufferWriter("chemin.txt");
    methode = uneMethode;
    eps = unEps;
    n = unN;
    solExacte=uneSolExacte;
    y=z;
    Date time =new Date();
    Vector valeur = new Vector();
    valeur.add(new Double(eps));
    valeur.add(new Integer(n));
    valeur.add(new Integer(solExacte));
    valeur.add(new Integer(methode));
    String time_string = time.toString();
    valeur.add(new String(time_string));
    //writing to variables file
    BufferWriter writer = new BufferWriter("variables");
    writer.write(valeur);
    Now it is the class Bufferwriter:
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.Vector;
    import java.io.File;
    public class BufferWriter {
    private String fileName;
    BufferedWriter w;
    public BufferWriter(String name) throws IOException {
    fileName=name;
    w=new BufferedWriter(new FileWriter(new File(fileName)));
    public void write(Vector v) throws IOException {
    String string;
    for (int i=0; i<5; i++) {
    string=((v.get(i)).toString());
    w.write(string,0, string.length());
    w.newLine();
    w.flush();
    public void close() throws IOException{
    close();}

    try
    w=new BufferedWriter(new FileWriter(fileName, true));
    The Constructor you want is ..
    FileWriter
    public FileWriter(String fileName,
    boolean append)
    throws IOException

  • Search for a String in a File?

    hi all
    is there a methid in java with which i can open a file and
    search for a specified string in the file? i also have to
    replace the String then.
    Thanks angela

    There is no magic method that can do all this for you. First you need to create an inputstream from the file you want to read. Then you can read it (without necessarily store the whole file in memory), until you find a match. If you want to replace the string with another string of the same length, you can use RandomAccessFile. If not, then you will have to move all the rest of the file forward or backwards when you replace the string, or write the whole file modified to a new file and then delete the old file before you rename the new updated file.
    Or you can depending on what you do, append changes to the end of the file, more or less like what is done with Word documents. And then only once in a while update the file with all the appended changes.

Maybe you are looking for

  • Appointments in BB won't sync to Outlook / duplicates

    HI all I have two questions. 1. I have a number of appointments on the BB which don't transfer to Outlook when I sync. I have tried adding text to the comments to try to trigger a sync (as it's changed) but it makes no difference. Any ideas? 2. I hav

  • Canon MX310 connected to Time Capsule problem

    I have a MX310 connected to the USB on the time capsule but still cannot use the printer on my network. I can go to system preferences and add it, but cannot print. Please help. Eric

  • Using Jboss Seam in an OC4J

    Good morning everyone, i need some help because i've tried to use the jboss seam framework in a web app to run in an OC4J server using jdeveloper 10 and when i execute the start page i get the following stack trace: GRAVE: [current-workspace-app] Se

  • Using to Time machine to get file that was saved over by same named file

    I accidentally deleted a file by naming a file the same name. Is it possible to go back and get one file using Time Machine? If so how do I do that? Thanks, Pat

  • Why record had been unlock in Oracle Apps form?

    I have a problem with lock in oracle apps forms. The problem occurs with all forms in the Oracle Financials (forms with standard oracle apps user-exit), the problem does not occur with standard Oracle default form (outside of the oracle apps, form wi