File copy/move thru java

Hi,
My code is something like this..
Which is trying to copy or move a file from one location to other.
Problem is I do not see the last modified date getting preserved,
in the copied file.
Why does this happen ? and how to preserve the last modified date
to copied file ?
File fTempRead = new File(fFrom.getAbsolutePath(), filename);       
File fTempWrite = new File(fTo.getAbsolutePath(), filename);
if (fTempRead.canRead()) {
            lastmodified = fTempRead.lastModified();
            fTempWrite.setLastModified(lastmodified);
            RandomAccessFile randomWrite = new RandomAccessFile(fTempWrite, Messages.getString("FileIOHandler.14")); //$NON-NLS-1$
                FileChannel fWriteChannel = randomWrite.getChannel();
                RandomAccessFile randomRead = new RandomAccessFile(fTempRead, Messages.getString("FileIOHandler.15")); //$NON-NLS-1$
                FileChannel fReadChannel = randomRead.getChannel();
                FileLock readLock = fReadChannel.lock(0,fTempRead.length(), false);
                FileLock writeLock = fWriteChannel.lock(0, fTempWrite.length(), false);
                long fLength = 0l;                                          
                byte by[] = new byte[1024];               
                int byteread = 0;                              
                while ((byteread = randomRead.read(by)) != -1)     {
                    randomWrite.write(by, 0, byteread);               
                readLock.release();
                writeLock.release();
                randomRead.close();                    
                randomWrite.close();
                if(move) {
                    boolean r = fTempRead.delete();
                if(!r) {
                    throw new FileMoveException(sb.toString());
        }

I'm not sure, but I would imagine that if you first setLastModified, and then write the file, the lastModified will be set again by the write.
Try calling setLastModified after you're done writing. (Not sure if you need to do it before or after close(). Try it each way.)

Similar Messages

  • Creating XML file in Project folder thru Java Program

    hi,
    i need one help. i need to create XML file in web://<Project Folder> in xmII thru Java Program. i created one java code and i am able to access XML file that is in c drive. i created jar file for this and placed as action block in Transaction and this working fine. but problem arises when i give file path in java code as web://<folder name>/file.xml which is in Web folder of project in xMII.
    How to access the file that is inside web folder from java code.
    regards
    senthil

    Hi Senthil,
    you can address the files that inside the MII workbench are viewed as "web://..." like this:
    http://<server>:<port>/XMII/CM/<Project>/<Folder>/<Filename>
    The workbench helps you find the correct filename:
    - open the WEB tab in the workbench
    - right-click on the filename
    - select "Copy Link" from the pop up
    Now you have the correct link in your clipboard.You can use the "web://" only inside MII.
    Michael

  • How do I copy/move files?

    What class do I use to copy/move files? I looked in java.io.file but I didn't see anything appropriate.

    Thanks for the point about NT and AIX. The exact reason I'm looking at this is to develop a stored procedure in an Oracle DB which will assist with backup operations on both NT and AIX. Thus whatever I do needs to work both places. We already have OS specific scripts that I'd like to get rid of . . .

  • Does File.renameTo() move files smartly or does it do a dumb copy/delete?

    I have to move very large files to a different folder within the same file system, in Solaris (actually a mounted NFS-based Filer - that supports NFS RENAME), instantaneously.
    This is possible if the O/S level call is smart enough to leave the physical file where it is and just change the file handle information.
    So... are Solaris and Java smart enough to do this automatically when we call renameTo()? Or is it using the brute force method?
    If it is using the brute force method, are there any issues I need to know if I use the exec() method to spawn a Unix process to do the move? (I ask because somebody in my office thinks that Java has problems with 'hung processes' when it spawns calls to Unix commands in Solaris - I have not experience this behavior personally)
    Thanks,
    Bruno

    I had tested, with a 100Mb file, all within a single filesystem, with the following results:
    Unix 'cp' command - on Solaris w/ Filer: 2-4 seconds
    Java renameTo() - on Solaris w/Filer: 4milliseconds
    Java renameTo() - on Windows w/LocalDisk: 0milliseconds (or more correctly < 1)
    From that it 'looks like' the renameTo() command when applied to moving a file withing a single filesystem will leave the file in place and simply change the file handle information.
    I posted because I wanted to be absolutely certain. There is a fairly dumb unix script that I have no control over to moves the files from my 'destination folder' into an archive. Corruption could have happened if the file was still being physically copied by my app (as opposed to the file handles) when the other process 'found it' in the directory and tried to grab it. But since - as you indicate - renameTo() only changes the file handles... that script can't see the file until it is fully available. Much safer.
    Thanks for the confirmation.
    Bruno

  • Files.copy java.nio.file.AccessDeniedException

    Hello everybody,
    I hope you are well, Me not.
    I use this method to unzip
    public void deziper(final Path zipFile, final Path destDir) throws IOException*
              // On crée un FileSystem associé à l'archive :
         try ( FileSystem zfs = FileSystems.newFileSystem(zipFile, null) ) {
         // On parcourt tous les éléments root :
         for (Path root : zfs.getRootDirectories()) {
         // Et on parcourt toutes leurs arborescences :
         Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
         private Path unzippedPath(Path path) {
    return Paths.get(destDir.toString(), path.toString()).normalize();
         @Override
         public FileVisitResult preVisitDirectory(Path dir,
         BasicFileAttributes attrs) throws IOException {
         // On crée chaque répertoire intermédiaire :
         Files.createDirectories(unzippedPath(dir));
         return FileVisitResult.CONTINUE;
         @Override
         public FileVisitResult visitFile(Path file,
         BasicFileAttributes attrs) throws IOException {
         // Et on copie chaque fichier :
         Files.copy(file, unzippedPath(file), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
         return FileVisitResult.CONTINUE;
    Replace all files work well, but when application try to replace Executable Jar File in same directory This error is thrown
    09oct.2012 13:52:12,484 - 0 [AWT-EventQueue-0] WARN barakahfx.ModuleUpdater - Exception
    java.nio.file.AccessDeniedException: G:\Program Files\Djindo\Imanis\Djindo.jar
         at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
         at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
         at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
         at sun.nio.fs.WindowsFileSystemProvider.implDelete(Unknown Source)
         at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(Unknown Source)
         at java.nio.file.Files.deleteIfExists(Unknown Source)
         at java.nio.file.CopyMoveHelper.copyToForeignTarget(Unknown Source)
         at java.nio.file.Files.copy(Unknown Source)
         at lib.GererFichier$3.visitFile(GererFichier.java:167)
         at lib.GererFichier$3.visitFile(GererFichier.java:150)
         at java.nio.file.FileTreeWalker.walk(Unknown Source)
         at java.nio.file.FileTreeWalker.walk(Unknown Source)
         at java.nio.file.FileTreeWalker.walk(Unknown Source)
         at java.nio.file.Files.walkFileTree(Unknown Source)
         at java.nio.file.Files.walkFileTree(Unknown Source)
         at lib.GererFichier.deziper(GererFichier.java:150)
         at barakahfx.ModuleUpdater.demarrerUpdate(ModuleUpdater.java:98)
         at barakahfx.AppliCtrl.demarrer(AppliCtrl.java:92)
         at barakahfx.BarakahFx$1.actionPerformed(BarakahFx.java:56)
         at javax.swing.Timer.fireActionPerformed(Unknown Source)
         at javax.swing.Timer$DoPostEvent.run(Unknown Source)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
         at java.awt.EventQueue.access$200(Unknown Source)
         at java.awt.EventQueue$3.run(Unknown Source)
         at java.awt.EventQueue$3.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Thank you very match
    Edited by: 964115 on Oct 9, 2012 5:39 AM
    Edited by: 964115 on Oct 9, 2012 5:40 AM
    Edited by: 964115 on Oct 9, 2012 5:46 AM
    Edited by: 964115 on Oct 9, 2012 5:55 AM

    Looks like you are trying to move the jar file you are executing and Windows has placed a lock on it. As far as I am aware there is no simple way round this. Why do you think you need to do this?

  • Delete partially copied movie file from iPhone. Shows grayed out in Videos on the iPhone but it doesn't show up in iTunes.

    Hello.
      I have synced my iPhone 4S with iTunes and I got an error while copying one movie. Now this movie shows up grayed out in videos on the iPhone but NOT in iTunes. Hence, I cannot delete this partially copied movie from my iPhone. And since it is grayed out, the right-to-left swipe does not work. I have resynced with "no movies" option so that every movie would be deleted and indeed every movie was deleted except for the problematic one. I rebooted the iPhone several times in case it was a glitch. No success. I even tried tools like iExplorer and DiskAid but I cannot find this **** file. Is there any way to delete this partially copied file from the iPhone without having to restore it?
    Regards,
    HawkeyeQ

    Hi adtsalmon,
    You can only watch the movie on the device you rented it on. Here's a snippet from the Apple Support site (italics mine):
    If you download a rented movie on your computer: You can transfer it to a device such as your Apple TV (1st generation), iPhone, iPad, or iPod if it’s a standard-definition film (movies in HD can only be watched on your computer, iPad, iPhone 4 or later, iPod touch (4th generation or later), or Apple TV). Once you move the movie from your computer to a device, the movie will disappear from your computer's iTunes library. You can move the movie between devices as many times as you wish during the rental period, but the movie can only exist on one device at a time.
    If you download a rented movie on your iPhone 4 or later, iPad, iPod touch (4th generation or later), or Apple TV: It is not transferable to any other device or computer.
    Here's the link to the Movie Rentals FAQs site FYI:
    http://support.apple.com/kb/HT1657
    Hope this helps!
    Cheers,
    GB

  • Copy/move file on application server

    Hey guys,
    is there an easy way to copy/move a file from one directory on application server to an other directory? I know i could use the commands OPEN DATASET and so on. Is there an other way to do this via a function module?
       thx,
         M.
    Moderator Message: Please search before posting, this has been discussed many times in the forum. All points unassigned
    Edited by: Suhas Saha on Aug 13, 2011 10:28 PM

    Hi ,
    As you know about the open dataset way of doing this ...You need another way and that will be as mentioned in the link below .....
    [Copy one file to another on application server |Re: Move  file from one folder to another floder in application server;
    Hope it helps ....
    Thanks,
    Anjaneya
    Edited by: Anjaneya Bhardwaj on Aug 13, 2011 1:02 PM

  • How to use the Microsoft File Copy dialog box  in Java ??

    Can anyone tell me if it is possible to use the Microsoft File Copy dialog box (the one with the animated gif of the paper flying from one folder to anaother) in a Java.
    Many thanks

    And in any case, in any version of Windows that I've looked at, the file copy animation is an AVI, not a GIF.
    db

  • Please help how to run System commands and batch files thru java program

    Sir,
    I want execute OS commands like dir,cls..etc and batch files,.exe filesthru java program.
    I have tried it sofar thru Runtime.getRuntime().exec("execute.bat");
    but it is not working.anybody knows about how to run the system commands thru java please give me the code.
    thank you,
    regards,
    j.mouli

    I've seen other posts with this questions, and answers. Unfortunately I didn't pay much attention. But the basic idea is to exec command.com and pass the specifc batch or command as an argument.

  • Error message when copying .mov files

    Hello,
    I'm trying to copy .mov files to back up from my desktop and from an external hardrive (250gb) to a new external hardrive (350gb) but each time I am getting the an error message saying the operation can not be completed due to unexpected error (error code 0). The files i am trying to copy are between 7gb and 20gb. Does anyone what what the error message means or how I can get around it please?!
    Thanks!

    If you want to use large files you have to reformat it. It will erase any data that is on the drive, If the drive will be used only with OSX, format it as Mac Extended (HFS+) Journaled with the GUID partition table.
    Start Disk Utility (Utilities Folder). Select the drive in the left column (be sure to select the drive, all the way at the left, not the volume indented below it). Select the "Partition" tab. Set "Volume Scheme" to "1 Partition". Click the "Options" button. Select "GUID Partition Table". Click the "OK" button. Enter the volume name and click the "Apply" button.

  • Copying movie files into a presentation

    Hi.
    I have a keynote presentation which includes lots of pictures. When I saved my presentation, I saved it with the option to copy the image files into my presentation document.
    However, I would like to copy some movie files into the presentation as well, but I do not want the movie files to be copied into the keynote presentation document.
    Is there anyway I can do this? If you have any suggestions, please let me know. Thank you very much.

    Keynote ALWAYS copie images into the file (except the theme images from the built-in themes, but it always copies YOUR images into the file). When you first saved it, did you check the box that said copy movies and audio into the file? If you did NOT check this then you're fine. If you did, you might have to make a new file and copy over your slides, then save it and make sure that box is UNCHECKED when you save it the first time.

  • Cannot copy .mov & .mpeg files to iPod 80

    Hello
    I have just bought an iPod Video 80 gb.
    I have some .mov & .mpeg files on my iTunes library. But when I try to copy those files to my iPod, a message appears:
    "filename" was not copied to the ipod "My iPod" because it cannot be played on this iPod.
    So I cannot copy those files to iPod. But I can copy .mp4 videos to iPod without any problem.
    Why is this happening? How can I copy .mov & .mpeg files to my iPod?
    I am using the latest iTunes, 7.0.2.16. Also my iPod has the latest software, 1.2.1.
    Thanks

    Have you looked at the troubleshooting document? "Disk cannot be read from or written to" when syncing iPod

  • Fail to copy mov /videon file over 400mb from iphone 4s to my pc(Shows 0kb after copy), but those below 400mb can be copied successfully

    fail to copy mov /videon file over 400mb from iphone 4s to my pc(shows 0kb after copy), but those below 400mb can be copied successfully

    Sorry, even over 350mb fails

  • Copy/Move files with FIFO-Buffer/Pipeline?

    Greetings,
    I'm looking for a way to copy or move files in the follwoing way:
    1) select target directory
    2) put files in a buffer. the files will be copied/moved to the target directory one after the other (FIFO)
    I think this would be a convenient feature for a file manager but I have not found one which works that way. Command line solutions would also be appreciated.
    Thanks,
    Beezle

    karol wrote:Would 'cp something_1 somewhere && cp something_2 somewhere && ...' do the trick?
    No, because I want the first file/folder to be copied/moved while I am still doing the selection in order to save time.
    Sorry for the confusion. The files should not actually be copied into a buffer, it only keeps in mind which files/folders I wish to copy/move. When a new file/folder is selected, it does not start copying/moving immediately but waits until the previous files/folders are done. The benefit would be that no parallel actions occur (but I can still select files/folders at my own pace and copying/moving occurs while I am still selecting).
    The rox-scripting idea sounds pretty good. I briefly tried writing a pygtk script but could not get drag and drop to work.
    Thank you.
    edit: It's not like I'm copying and moving files around all day like mad, I just want to be as efficient as possible.
    Last edited by Beezle (2012-01-13 16:27:15)

  • Crackling sound on file/dir copy/move

    I've noticed for several months that when I copy/move files/dirs I get a distinct short 'crackling' or static sound. Very short (under 1 second) but loud and piercing. What associates a sound with an action (like copy/move)?
    Anyone else?
    iMac Mac OS X (10.4.9)

    I've noticed for several months that when I copy/move
    files/dirs I get a distinct short 'crackling' or
    static sound. Very short (under 1 second) but loud
    and piercing. What associates a sound with an action
    (like copy/move)?
    System Preferences > Sound > Sound Effects: the “Play user interface sound effects” checkbox.
    Dual-core G5 2.3 GHz   Mac OS X (10.4.9)   2.5 GiB RAM

Maybe you are looking for