How to overwrite a file?

Dear Sir,
I'm writing a program which read a txt file (e.g.infile.txt) and before quit the program, I need to rename the file to infile.old and create another infile.txt. I used file.renameTo(newfile) to rename the file. However, when I run the program the 2nd time, I found that the infile.txt cannot be rename since the infile.old already exist (that means the infile.old cannot be overwirte).
Question 1:
In the program, I need to find whether an infile.old already exist. Which method can be used and what's the synthx?
Question 2:
If the program check that an infile.old already exist, do I need to delete it (before doing the rename) or use another method to overwrite it?
Thanks a lot!

Question 1:
In the program, I need to find whether an infile.old
already exist. Which method can be used and what's
the synthx?Look at the api for the File class it should be pretty clear what method to use.
Question 2:
If the program check that an infile.old already exist,
do I need to delete it (before doing the rename) or
use another method to overwrite it? I would delete the file first, if you just overwrite it and your new data is smaller than the current data in the file, you will have leftovers from the old data at the end of your new data.

Similar Messages

  • How to overwrite source files, or use source file names?

    Hi all
    I would like AME (5.5.1.12, under Windows 7) to overwrite the source files that it is encoding, or if that's not possible, save the exported files to a different folder with the same file names as the sources.
    However I can see no way to do this without manually specifying a file name for every file. I need to process 400 files so this is not practical.
    Currently AME automatically adds a "-1" suffix to the exported file name, whether it's saved in the same folder as the source or a different folder.
    Can anyone advise, please?

    Hi Jim,
    Thanks for the reply. However, overwriting source files during a batch process is a common feature in audio/video software. It's possible in Audition, for instance, as well as in third-party programs such as Sound Forge, Wavelab and Samplitude.
    Presumably in these cases the software writes to a temporary file, either in RAM or on the hard drive, before deleting the original and replacing it with the new one.
    I'm surprised to hear that AME can't do this for conversions that stay within the same file format (such as the bit depth of a wave file).

  • Overwrite executable file when the process is running

    When a program is still running (a UNIX server process), can I overwrite the executable file with a newer version?
    also, can i overwrite a shared library file that is being used by a currently running process?
    I don't think it is a good idea. But what happens?
    This is my first posting. Sorry if this is not the right place.

    Your question is about Unix. This forum is about C++ programming. You are more likely to get comprehensive answers in an OS forum. But I can tell you part of the answer.
    Remember that in Unix, a directory entry is separate from the file it refers to. One file can be referred to (linked to) by more than one directory entry. The file system keeps a count of how many directory entries refer to a file, and how many processes currently have the file open. When the directory count and the process count both go to zero, the space used by the file is reclaimed.
    The answer to your questions depend on exactly how you overwrite the files. A typical way to overwrite a file is to delete the orginal file and create a new file with the same name in the same directory. Most applications that seem to be changing the contents of a file actually delete the original and create a new file.
    Suppose you create a new version of /mydir/mylib.so, which is currently in use by process1. The directory entry /mydir/mylib.so now points to a different file, but process1 continues to use the old file, which currently has no name, and no directory entries pointing to it. If you start a new process that depends on /mydir/mylib.so, it will use the new library version. When process1 exits, the last reference to the original version disappears, and the disk blocks used by the original version will be reclaimed.
    If you used some other mechanism to update a file, such as a binary editor that changes disk blocks directly, you could create inconsistencies for processes that are using the file. Whether processes using the file see a change depends on whether they go back to refer to the file, or have finished reading it.

  • How to save for web AND overwrite original files with Action?

    Hello,
    I want to compress a batch of images with "save for web" using a Photoshop Action, and I also want to preserve my folder structure and overwrite source files. The structure is important because it's complex and needs to be structured this way.
    The Problem:
    When I choose "save for web", I must define a destination. What happens is all optimized files from within the structure are saved in a single location.
    Here's an example of the folder structure
    Folder A
         - Subfolder A1
         - Subfolder A2
    Folder B
         - Subfolder B1
         - Subfolder B2
              -Subfolder B2.2
    Folder C
         -Subfolder C1
    Summary
    Is it possible for me to use a Photoshop Action with "save for web", and overwrite my files without moving them from the structure?

    No need to re-invent the wheel.
    Just learn how to use the Image Processor, Image Processor Pro, or Dr. Brown's Services 1-2-3 in Photoshop and/or Bridge.

  • How to delete or overwrite .csv file

    hi...
    i need some help here..can anyone teach me how to delete or overwrite an existing .csv file.?..in my .csv file there will be two columns which is column 1( 8 length) and 2 column ( 4 length).
    please...i need the answer asap..really appreacite your help..thanks...

    Well, deleting or overwriting a file should not depend on the size of the columns. You just overwrite the file with the new data. What have you tried so far?
    If you want to overwrite individual data points, you would read the file, modify the data in memory, and overwrite the file with the changed data. Overwiting individual values directly is only recommended for binary files unless you can guarantee that each value occupies a fixed number of characters and the offset can be calculated from first principles.
    LabVIEW Champion . Do more with less code and in less time .

  • HT201274 how to recover overwritted backup files in itunes

    how to recover overwritted backup files in itunes, it is not showing older backup files in itunes backup

    If the backup files are no longer there, unless they have backed up by the user there is nothing to restore.

  • How to overwrite the xml file...

    Hi,
    can any one help me how to overwrite the xml file.....
    ~~Sk

    Flash Player cannot write XML files at all. but using
    php+flash we could do it .

  • How to disable "overwrite exisintg files" checkbox from Upload.aspx

    Hi Folks,
    I have a requirment to disable 'Overwrite existing files' check box from upload.aspx for only 2 specific libraries and it should be in visible for rest of libraries.
    could you please share the code snippet / any other suggestions to make it full this requirement.
    Thanks,
    janaiah

    Hi 
    you can use jquery to do so.
    $(document).ready(function()
        var
    form = $('form');
        if
    ( form.attr('action').indexOf('YOUR 36 character List ID - Without Braces') > -1 )
            var
    checkbox = $('#ctl00_PlaceHolderMain_UploadDocumentSection_ctl03_OverwriteSingle');
            checkbox.prop('checked',false);
            checkbox.parent().hide();
            var
    multiple = $('#ctl00_PlaceHolderMain_UploadDocumentSection_ctl03_UploadMultipleLink');
            multiple.hide();
    https://sharepoint4u.wordpress.com/2013/08/13/how-to-disable-overwrite-exisintg-files-in-a-library/
    Regards,
    Rajendra Singh
    If a post answers your question, please click Mark As Answer on that post and Vote as Helpful
    http://sharepointundefind.wordpress.com/

  • How to programmatically overwrite the file in Labview?

    Iam using Copy.VI for copying a file from one directory to other. If the file is already exist in destination directory, Copy.VI generates an error of "10". I wanted to overwrite the file which is already exist. Does anyone has solution. I have attached a file which is written in Labview 6.1.
    Attachments:
    Copy_File.vi ‏21 KB

    Always run a delete first, or alternatively; run a delete if the copy fails with error 10 and then redo the copy operation...
    MTO

  • How to append a file in a trigger?

    I'm writing from a table to a file, and have created a trigger that works great...however, I need to append the file so it doesn't overwrite the file every time the trigger fires.
    Here's the code...but I can't figure out how to append the file instead of just write to the file:
    CREATE OR REPLACE TRIGGER checkout_trg
    AFTER UPDATE OF movie_qty ON mm_movie
    FOR EACH ROW
    DECLARE
    fh UTL_FILE.FILE_TYPE;
    BEGIN
    IF :NEW.movie_qty=0 THEN
      fh:=UTL_FILE.FOPEN('ORA_FILES','chekcout.txt','w');
      UTL_FILE.PUT_LINE(fh, 'Date: '||sysdate||', Movie ID: '||:NEW.movie_id||', Quantity: '||:NEW.movie_qty);
      UTL_FILE.FCLOSE(fh);
    END IF;
    END;
    /

    > It's for an assignment...I think thye're just trying to show us what's possible.
    Just as it is possible to show a learner driver to jump a red light, drive on the wrong side of the road, or do doughnuts in an intersection...
    But none of this will make that learner driver a good driver. Never mind able to correctly handle high performance cars on the professional circuit.
    Sorry mate - what they are showing/teaching you is pure bs. A trigger is not the "same thing" as a callback event in client programming.
    And feel free to give them this URL and tell them that I think they are full of it. Let's see how they defend their non-real world, totally irrelevant and wrong assignments in this very forum.

  • "Smart update" question or how to overwrite the library in current use

    Hello,
    I would like to add a "smartUpdate" feature to an application i.e.
    1. Read an updated library from the web (e.g. as archive- zip)
    2. Extract files from archive and write them to a local drive.
    3. After all the files are written, close the appliaction and restart it.
    #1 is easy enough, there problems is with #2 and #3.
    I will need to overwrite jar file that the running application is using.
    Does anybody has experience with this. Any ideas how to do this.
    Thank you.
    Leo

    Appreciate any other ideas...If you have to exchange classes in an application while it is still running, this will always be a bit tricky (if not
    impossible). It is much easiser to close and restart the application (= make the OS call the Java-interpreter again). But if you decide, that restarting from the OS is not possible, there is some work to do :-)
    There are three main problems:
    1. If your classes are loaded from Jar-files, the Jar-files will be locked by the java-process. Once a class has been loaded from a Jar-file, that file is write-protected
    2. Java will not reload a class that it has already loaded, even if the Class- or Jar-File has changed
    3. Even if the class would be reloaded, this could not affect any instances of these classes.
    Problems 1 and 2 can be solved by using a custom ClassLoader (this is still 100% pure Java, no hack or
    something).
    This custom ClassLoader could be written in a way that it could close the Jar-Files on demand (closing the Jar-File every time a class has been loaded would slow down class loading significantly).
    To force reloading (=using the new jar-file) you would have to instantiate a new ClassLoader (= another instance of your own custom ClassLoader). This new ClassLoader will use the new versions.
    The third problem is just a matter of your application; you must ensure that it re-instantiates everything with the new ClassLoader.
    So, it would be something like:
    //Create custom CLassLoader
    MyClassLoader cl = new MyClassLoader();
    //--- start update code (assuming my.package.MyClass1.main will receive the new jar-file)
    Class mc = cl.loadClass( "my.package.MyClass1");
    Method main = mc.getMethod( "main", new Class[]{ String[].class } );
    main.invoke( null, new Object[]{ new String[0] } );
    //--- overcome write-protection
    cl.closeFiles();
    //--- now copy the new Jar-File into the appropriate directory
    //--- dispose first ClassLoader and create a new one
    cl = new MyClassLoader();
    //--- start app (assuming my.package.MyClass2.main is the "real" application)
    Class mc = cl.loadClass( "my.package.MyClass1");
    Method main = mc.getMethod( "main", new Class[]{ String[].class } );
    main.invoke( null, new Object[]{ new String[0] } );All this ClassLoader stuff is a bit tricky, but this kind of "smart update", where you exchange classes while the VM is still running, is not a trivial problem (though
    it's quite common if you're write application servers).
    HTH
    Matthias

  • How to create a file after ElapsedTime

    Hi, I have a situation where my BPEL process consumes messages off of a queue and creates a output file using them via a FTP Adapter. The number of messages vary greatly depending on the day and the business needs only 1 file a day with the appropriate dateTime stamped to it. I tried using the elapsedTime option on the FTP adapter but it seems to be waiting for invocation before creating the file. I set the time to 2 minutes but instead of creating the file after 2 minutes of inactivity, it waits for a message to be triggered with more than 2 minutes time difference from the last one. Since the messages come in a burst on this queue, the next message wont come in until the next day for the file to be triggered.
    I also tried appending to a file but this is over a SFTP connection so it just kept overwriting the file and in the end I just have 1 record on the file. Any suggestions on this would be really helpful as to how should I go about creating this file in a way that it captures all the messages for today and creates the file the same day as well. Thanks!

    like an action class?Huh? What exactly is your requirement?
    Creating a file is usually done with java.io API. Read the java.io tutorials how to play with files.

  • Overwrite Exisiting Files - error

    I see this questions has come up a few times, but having read the answers it seems i still have a problem.  can someone clarify if i am making an error my workflow please?
    Take images in Folder XXX and develop them
    Export these images to a new folder YYY.  add to catalogue not ticked
    Syncronise YYY and bring in new images.  Apply a develop preset to these images on import
    Export the images in YYY with preset applied as jpegs to YYY for external use.  Select "Overwrite without Warning"
    Error comes up saying this cannot be performed as woudl replace exisitng photo
         My understanding from other threads is this eror should only happen if you try to replace an original, but was designed for exactly my purpose when you are operation on copies.  I am just owndering how LR is meant to know that the imported copy is a copy not an original.  What attribute would tell in that as importing through syncronisation is the same process.  If I used the "add to catalogie" in stage 2. does this let LR know it'sa copy?  If so I could add my preset manually?
    i am using LR 2.5 on Vista 32 bit
    Thanks for any advice.
    Mike

    The bug that allowed overwriting of files present in the catalog was resolved some time ago. LR has no idea what "originals" are, it just won't let you over write files present in its catalog and a good thing to! The over write function is to over write exported images, I use it all the time and it works fine. So if I want a set of images for one purpose I export them to a folder, if I then need them in a different size or whatever I just use the same folder and over write the previously exported files. No need to import these files into LR as I have the "originals" and can always make virtual copies if I need different versions in LR

  • How to write text file in Shockwave?

    Does anybody know how to write text file in Shockwave to
    user's disk?
    Thanks in advance.

    Those Xtras can wreak to much havoc when used with the wrong
    intent.
    What you can do is write with setpref and store a list of
    saves and the
    saves itself seperatly. Then you'd have to build your own
    save/open
    dialog to let the user:
    * pick a previously saved file to load or overwrite
    * have the user type the name of a new file to save.
    Only thing that remains is that the user cannot decide where
    the files
    are saved.
    Manno
    SiuLinda wrote:
    > Thanks a lot for your reply.
    > Yes, cookies is good but I have to write a program to
    save the text file in
    > where the user wants, user can open these files later if
    they like, like using
    > Filextra and Fileio, but I found all of these xtras seem
    to be not supported in
    > shockwave.
    >
    Manno Bult
    [email protected]

  • How to compare two files char by char

    Hi,
    I want to compare two files and after Comparison i want all the differences in the new file has to be updated to old file (Without deleteing the contents of the file)?
    Any help will be appriciated.
    Thanks.

    I think i have to elaborate my question�.. for
    example take a file called xyz.xml which contain some
    data which I don�t want to get deleted� after some
    days this file has been modified (i.e. some more data
    has been added) . Now without overwriting the file
    /deleting the earlier contents of file xyz.xml. How
    do I update xyz.xml file?
    Now I think iam clear.
    Thanks.This does not make sense at all! Either your file has been changed or it has not. If it has been changed then there is nothing to do. If it has not been changed then there is nothing to do.

Maybe you are looking for

  • SunOS 5.10 spawns multiple PID's for same java process

    On SunOS 5.10 I see same java process having multiple PID's. ps -ef lists out the same java process running from same path with multiple PID's. What can be the reason for this? Please let me know if you need some more information..... Edited by: saya

  • My Iphone 5 screen wont turn onj

    When i was trying to open an app the screen went black and then the folder screen (where all the apps are) came on and i pushed the ome button and then the screen just turned off. My Iphone 5 is on, working, i can hear all the notifications when they

  • CS4 Dreamweaver not replacing paths for images/links

    New Windows 7 machine with CS4 Web Premium.  When using Dreamweaver, and, for example, replacing an image or a link in the design window using the properties...  I click on the image, click the browse button, select the new file (I've tried hitting O

  • VMWare Fusion version 3.1.3 compatible with MAC OS X Lion

    Hi, does anybody know if VMWare Fusion version 3.1.3 is compatible with MAC OS X Lion? I need to emulate windows 7 on my mac. Thanks!

  • Return order - your reference field is grey

    hi, I want to make use the field "your reference" in item -->  PO tab --> your reference. however, this field is grey in return order. how can I make it changable. Thanks