File renameto issue

I have been tracking this down for a couple of days now and thought I would ask the forum for their input.
I have a very simple process that opens a file, reads in the data, writes some data to a DB, and them moves the file to a processed folder.
SOME of the instances I have running that are performing this process are moving the files into the wrong directory. I am going round and round with this
being an OS issue and/or jvm issue. The oddest thing is that the wrong directory that some of the processes write their files to is always the last
directory created under that particular filesystem.
System:
sun-jdk-1.5.0.06
Linux; SMP; 2.6.12
Process is run via shell script every 10 minutes where a directory is passed to the process, the process then looks in the directory for files,
does what it does, and then renames the file. ex. "LogProcessor /var/log/10.5.1.2/". The process should move the file to the folder /var/log/10.5.1.2/processed,
instead it is moving the file to "/var/log/10.5.1.52/processed". All of the debug code you see below is telling me that everything is what and where it should
be, however, it is not.
Other information: There are about 15 independent processes running started by separate shell scripts and all should be reading and writing to their respective folders.
Any input would be greatly appreciated.
CODE:
File dirName = new File(args[0]);
String[] files = dirName.list();
//test if directory actually has something we want
               if (files != null) {
                    // loop through list of files found in directory
          for (int i=0; i<files.length; i++) {
          // Get filename of file or directory
               if(debug)
                    System.err.println("File Extension: " + files.substring(files[i].length() - 3));
               // test last 3 characters for file extension we need
               if (files[i].substring(files[i].length() - 3).equalsIgnoreCase("log") || files[i].substring(files[i].length() - 3).equalsIgnoreCase("alm")) {
          fileName = args[0] + files[i];
               // Call each method respectively passing in all the local objects
               if (alarms) {
                                   logProcessor.alarmsProcessor(fileName, logFile, job, jobActions, errors, debug);
                              } else {
                                   logProcessor.storeLogsProcessor(fileName, logFile, job, jobActions, errors, debug);
               //SLD 11/28/2007: move the file to the processed folder after read
               File file1 = new File(fileName); //this file already existed on the file system
               File file2 = new File(args[0]+"processed/"+files[i]);
                    if (file1.renameTo(file2)) {
                         System.out.println("File "+files[i]+" Moved to processed folder "+ args[0] + "processed" + file2.toString());
                         System.out.println("From: " + file1.toString() + " To: " + file2.toString() );
                    } else {
                         System.out.println("File "+files[i]+" NOT Moved to processed folder "+ args[0] + " due to either permissions, folder nonexistant or file already exists");

Well, just to update the issue. The problem has been solved. There was an entry into the list of IP's that was 10.58.?.??, which in the unix world is a special character/place holder for all
files/folders that resemble it. This was wreaking havoc on my java program when moving files.
Thanks,

Similar Messages

  • File.renameTo method issue

    I have a Java program which processes upto 10000 text files a day. The average size of these files are 1KB to 2KB and the java program parses the contents of the text file, validates and loads them into a database table.
    The program outline is as follows
    File[] filesToProcess = sourceFolder.listFiles();
    int fileCount = filesToProcess.length;
    for (int i=0;i<fileCount;i++) {
    File currentFile = filesToProcess;
    MsgParser fileParser = new MsgParser(currentFile);
    if ( fileParser.isMessageValid()) {
    boolean uploadSuccess = fileParser.uploadToDB();
    if (uploadSuccess) {
    if (currentFile.renameTo(parseSuccessArchiveFile))
    logger.info("File successfully moved to archive folder);
    else
    logger.info("File cannot be moved to archive folder);
    } else {
    if (currentFile.renameTo(parseFailureArchiveFile)
    logger.info("Parser failed file moved to archive folder);
    else
    logger.info("Parser failed file cannot be moved to archive folder);
    The above program outline works well. However the renameTo method is not renaming the parsed files successfully on all occasions. There is no performance issue involved here as the files keep streaming in throughout the day and the program is able to handle the parsing of the file(s) in a fraction of second.
    The issue for me is that I keep picking the files to parse from the source folder at regular intervals ( after a full iteration of the files list, wait for 10 seconds before calling for a new set of files ) and cannot afford to have a failure in moving the file to the archive folder as otherwise, I end up parsing the same file multiple number of times, which I want to avoid.
    Can anyone shed some light on the behavior of File.renameTo and how to make it work successfully?
    Sundar

    I am making the code more readable for you all and corrected some typo errors...
    File[] filesToProcess = sourceFolder.listFiles();
    int fileCount = filesToProcess.length;
    for (int i=0;i<fileCount;i++) {
          File currentFile = filesToProcess;
          MsgParser fileParser = new MsgParser(currentFile);
          boolean uploadSuccess = false;
          if ( fileParser.isMessageValid())
               uploadSuccess = fileParser.uploadToDB();
          if (uploadSuccess) {
                if (currentFile.renameTo(parseSuccessArchiveFile))
                      logger.info("File successfully moved to archive folder);
                else
                      logger.info("File cannot be moved to archive folder);
          } else {
                if (currentFile.renameTo(parseFailureArchiveFile)
                      logger.info("Parser failed file moved to archive folder);
                else
                      logger.
                      info("Parser failed file cannot be moved to archive folder);
    }

  • Java.io.File renameTo does not work on Solaris

    Hi Experts,
    I have a code-piece which tries to move files from one directory to another on the SAME FILE SYSTEM using java.io.File.renameTo method.
    It works fine when there less no. of files in the source directory. But the renameTo does not work as expected when there are very huge no. of files(~40K) present in the source directory.
    I am aware that there is a known issue when one tries to use this method to move files across file systems OR if the file exists at the destination directory.
    But in my case the file system is the same and the there is no such file in the destination directory.
    I suspect some inode related issues. But not sure what it is exactly.
    Is there any limitations of renameTo?
    Please help.

    OK, we all now understand you have a problem in doing this, but without the specifics of the problem that you are experiencing, then it is fairly difficult to give you anything other than a guess. If you would like some specific and relevent answers, please supply specifics about how exactly the operation differs from your expected results. You should also post example code as it is almost always asked for eventually.

  • PS CS3, Camera Raw 4.6 Update and Nikon D810 NEF File Reading Issue

      Currently Have Photoshop CS3 & Adobe Bridge CS3 2.1.1.9.
    According to Adobe, Camera Raw 4.6 supports Nikon D810 NEF files.  I have downloaded Camera Raw 4.6 Update. When
    I try to open Nikon D810 NEF files, I get Photoshop CS3  error that says
    "cannot complete request your because it is not the right kind of
    document. These NEF files wont open in Adobe Bridge at all.  What am I doing wrong?

    Hey,
    Before I purchased, let me get your thoughts on another option that just occurred to me which involves:
    1)Editing my D810 NEF files in LR 5.6, which I have, then exporting/saving the edited files as JPEGs.
    2) Doing any additional editing, as necessary (i.e. that might require layering or selections..etc) , with the JPEGs  with Bridge or PS CS3. 
    This method wont involve any additional software purchase now.. right?    Am I missing anything.   here?    Since my final output to my customers are JPEGs any way, wont this work?   Will I be at any disadvantage.   Am I missing anything.   here? 
    From: ssprengel <[email protected]>
    To: charles cash <[email protected]>
    Sent: Monday, October 6, 2014 9:49 AM
    Subject:  PS CS3, Camera Raw 4.6 Update and Nikon D810 NEF File Reading Issue
    PS CS3, Camera Raw 4.6 Update and Nikon D810 NEF File Reading Issue  created by ssprengel in Adobe Camera Raw - View the full discussion  
    You can buy it from here:
    http://creative.adobe.com/plans
    Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at https://forums.adobe.com/message/6795004#6795004
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: 
    To unsubscribe from this thread, please visit the message page at . In the Actions box on the right, click the Stop Email Notifications link. 
    Start a new discussion in Adobe Camera Raw by email or at Adobe Community
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

  • Concurrent processing & file.renameTo(...)

    Hi,
    I've can successfully move a file in the single thread/process environment using file.renameTo
    However in the multithreaded/multiple process environment, the initial file is several MB (about 100mb). It is created on the fly outside of my thread and takes several minutes to build.
    I would like to rename it after the file is finished building.
    In my code I do the following:
    boolean success = false;
    while (! success)
    success = inputFile.renameTo(dest);
    QuickSleep(1500); // Performs a Thread.sleep in a try/catch
    I've seen some weird behavior however. On a windows box the renameTo seems to return false if the other process is still writing to the file. However on linux the .renameTo is returning true even though the file hasn't finished building.
    The end result on linux is I end up with two files. One that got renamed and is partially filled and the other original with the rest of the file.
    Is there a way to know when the file isn't being written by another process/thread?
    Thanks in advance.

    if by now you still have the problem (FYI this is working on AIX) have a look at my solution:
    for (int i = 0; i < dir.listFiles().length; i++) {
    try {
         Process p = Runtime.getRuntime().exec("/usr/sbin/fuser " + dir.listFiles().getAbsolutePath());
         p.waitFor();                              
         InputStream in = p.getInputStream(); // we have to read the stream to verify if there is a process id
         int c = in.read();
         String stream = "";
         while (c != -1) {
              stream = stream + (char)c;
              c = in.read();
         if (stream.trim().length() > 0) {
              logger.info("File: " + dir.listFiles()[i] + " is in use by process ID:" + stream);
              try {
                   Thread.sleep(5000); //sleep for 5 sec
              } catch (InterruptedException e){
                   // the VM doesn't want us to sleep anymore,
                   // so get back to work
              continue;
    } catch (Exception e) {
         logger.error("fuser exception: " + e.getMessage());

  • File.renameTo(File) doesn't change dirs on Linux?!

    Hi All,
    I'm trying to change a file's name and directory with File.renameTo but it doesn't work. It says in the manual that changing dirs is O/S dependent, so i guess it doesn't work on Linux.
    Is it correct? if so, what can be done to change a file's name and directory?
    File oldFile = new File(filePath);
    oldFile.delete();   // Delete old file
    File newFile = new File(newFilePath);     // This is the new file
    File tempFile = new File(filePath);          // Get name to renameTo
    newFile.renameTo(tempFile)                  // Try to rename

    Hmm, it worked for me, though I didn't try deleting the oldFile. A simple move from one directory to another was not problem, though. The rename would fail if the delete failed. You might check that.

  • SQL Server 2008 .MDF File attaching issue

    Hy all guys here is big Happy news about the SQL Server 2008 database.mdf file attaching issue on Windows 8.1 and SQL Server 2008
    I found the solution like this
    first you go to the directory of your computer and go to that folder where your database and other files are like
    folder having database and files then > Right click and > security > then give full rights from which user you LOGIN and then apply > ok after that go to SQL Server 2008 > Right Click > run as administrator
    Hurray your problem will be resolve I Resolved my issue too  thanks to providing every solution
    if you guys find solution please give me best regards thanks  

    Hi Farhan-Islam,
    Glad to hear that your issue had been solved by yourself. Thank you for your sharing which will help other forum members who have the similar issue.
    Regards,
    Lydia Zhang

  • File.renameTo

    Hi,
    Does file.renameTo work on AIX Server,and how much time will this method take to move a file of 35 million records?
    Regards
    KK

    NAME
    rename - rename a file
    SYNOPSIS
       #include <stdio.h>
        int rename(const char old, const char new);
    DESCRIPTION
    The rename() function changes the name of a file.
    The old argument points to the pathname of the file to be renamed.
    The new argument points to the new pathname of the file.
    posman@proli:~/ivan> df -k . /tmp
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/cciss/c0d0p3     16682556  14755300   1927256  89% /home
    /dev/cciss/c0d1p2     35539772  33619432   1920340  95% /
    posman@proli:~/ivan> cat x.c
    #include <stdio.h>
    int main() {
    int r =  rename("movethis","/tmp");
    if (r !=0) perror("rename");
    return r;
    }posman@proli:~/ivan> gcc x.c -o x
    posman@proli:~/ivan> ./x
    rename: Invalid cross-device link
    Edited by: BIJ001 on Oct 1, 2007 9:01 AM

  • File.renameTo() and locking

    Hi,
    I would like to rename file, but File.renameTo() will not work if the file will be locked by some other process. If other process has locked the file, I would like to wait for it to release the lock. So I have:
    FileLock lock = new RandomAccessFile(file, "rw").getChannel().lock(0L, Long.MAX_VALUE, false);
    file.renameTo(destFile);
    lock.release();But this does not work, because file is locked and renameTo does not work (returns false).
    What can I do to lock the file myself (wait for other locks to be released) and to rename it (rename does not work when file is locked).
    Regards
    Pawel Stawicki

    hi, I don't thik you have to lock the file yourself while renaming it because that is (from my point of view) an opperating system's job to do it.
    you could maybe make a
    while(! file.renameTo()){
    thread.sleep(1000);
    to wait till its unlocked.
    I'm not sure that helps but that's just an idea

  • File.renameTo() bugg? Leaves the file open

    I came across the strangest behaviour of File.renameTo() for the following steps:
    1. Rename a file - successful
    2. Rename the same file again - will fail. Also delete will fail.
    -------- some code ----------
    File file=new File("F1");//nonexistent file
    //write some to the file - just to make the file to be created
    RandomAccessFile rFile=new RandomAccessFile(file,"rw");
    rFile.writeBytes("Hello");
    rFile.close();
    //A successful rename
    boolean renamed=file.renameTo(new File("F2"));
    System.out.println("renamed="+renamed);
    //This is commented code for now
    //rFile=new RandomAccessFile(file,"rw");
    //rFile.close();
    //This rename fails!
    renamed=file.renameTo(new File("F3"));
    System.out.println("renamed again="+renamed);
    As it seems File.renameTo() sets the file to open, since neither renameTo or delete will work after a renameTo.
    BUT, if I uncomment the commented code, it will work again! I just open a dummy RandomAccessFile (FileInputStream would work as well I guess) and then close it, and somehow the file is set to closed again, and the second renameTo() will work.
    Is this a bugg in File.renameTo()? I run on windows XP and have java 1.4.1_02-b06. I couldn't find any comment about this in the Bug Database.
    Gil

    Aha! so the reason why the opening of the dummy RandomAccessFile did it in my previous code, was becase it created the old File "F1" again that could be renamed again. So the correct code should instead be:
    -------- some code ----------
    File file=new File("F1");//nonexistent file
    //write some to the file - just to make the file to be created
    RandomAccessFile rFile=new RandomAccessFile(file,"rw");
    rFile.writeBytes("Hello");
    rFile.close();
    //A successful rename
    File file2=new File("F2");
    boolean renamed=file.renameTo(file2);
    System.out.println("renamed="+renamed);
    //Now this rename also succeeds!
    renamed=file2.renameTo(new File("F3"));//do rename on file2!
    System.out.println("renamed again="+renamed);
    Gil

  • Recording File Size issue CS 5.5

    I am using CS 5.5, a Balckmagic Ultra Studio Pro through USB 3.0 being fed by a Roland HD Video switcher. Everything is set for 720P 60fps (59.94) and the Black Magic is using the Motion JPEG compression. I am trying to record our sermons live onto a Windows 7 machine with an Nvidia Ge-Force GTX 570, 16 GB of Ram and a 3TB internal raid array (3 drives). It usually works great but more often now when I push the stop button in the capture window, the video is not proceesed and becomes unusable. Is it a file size issue or what. I get nervous when my recording goes longer than 50 Minutes. Help

    Jim thank you for the response. I have been away and busy but getting
    caught up now.
    I do have all drives formatted as NTFS. My problem is so sporadic that I
    can not get a pattern down. This last Sunday recorded fine so we will see
    how long it last. Thanks again.

  • All of a sudden File compatability issues with IPhoto & digital camera

    Anyone have issues or solutions for solving file compatability issues with IPhoto & digital camera?  Worked okay for years but all of a sudden giving me error messages about file format.  My camera uses Jpeg.

    There is an issue ongoing  between 10.6 and Kodak cameras. Workround: use a USB Card Reader.
    Regards
    TD

  • I am having a file moving issue with Adobe Reader XI

    I am having a file moving issue with Adobe Reader XI on a Windows 7 32bit system. When Adobe reader is set as the default program for PDF files moving files from one directory to another takes over a minute, regardless of the size of the file. When the default handler is set to another program, like Nuance or PDF Creator, this is instant. What in Adobe Reader is causing this and what can I do to speed up file moving? Any help will be greatly appreciated. Thank you.

    I am using Windows 7 home edition and using Internet Explorer 10
    The PDF's are online on websites that I am trying to open.  Both on the site as well as trying in a new window.
    Thank you
    Jeff

  • Windows Update Helps with File Size Issues?

    I'm just wondering if anybody has recently noticed an
    improvement related to the file size issue variously reported
    throughout the forums?
    I ask because our IT folks distributed a Windows update on 2
    days last week and since the application of those updates I have
    not experienced the freakishly large file sizes and the related
    performance issues in Captivate. Unfortunately I don't have any of
    the details of what patch(es) were installed, as it was part of our
    boot script one morning and I didn't even realize it was updating
    until I received the Reboot Now or Later alert.
    Anyway, I was curious because I have experienced significant
    performance improvement since then.
    Rory

    If you are using a remote workflow ... designers are sending off-site editors InCopy Assignment packages (ICAPs) .... then they need to create assignments in order to package them for the remote InCopy user. So there's no need to split up a layout into smaller files or anything.  An assignment is a subset of the INDD file; multiple assignments -- each encompassing different pages or sections -- are created from the same INDD file.
    When the designer creates the assignment, have them turn off "Include original images in packages"; that should keep the file size down.
    Or -- like Bob said -- you can avoid the whole remote workflow/assignment package rigamarole all together by just keeping the file in a project folder in the Dropbox folder on teh designer's local hard drive, and have them share the project folder with the editors. In that workflow, editors open the INDD file on their local computer and check out stories, just as though they were opening them from a networked file server.
    I cover how the InCopy Dropbox workflow works in a tutorial video (within the Remote Workflows chapter) on Lynda.com here:
    http://www.lynda.com/tutorial/62220
    AM

  • E4200V2 file corruption issues

    Hello,
    I am getting file corruption issues when doing a file transfer onto the NAS (hard drive plugged into the router). Files are turned into folders while keeping the same filename. It happens occasionally.
    I have firmware: 2.1.39.145204 installed.
    Any remedy for this as it is a very serious problem.

    The only known solution is to call linksys and ask them for a replacement router model that does not contain the bug. See thread link for details.
    http://community.linksys.com/t5/Wireless-Routers/Media-files-changing-to-folder-types/td-p/504192/hi...

Maybe you are looking for