Results 1 to 2 of 2
  1. #1
    pjyelton is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default Problem with folder watcher

    Hello, new to Java but not entirely new to programming in general. This is my first application and am running into an issue. I'm designing my program to watch a specific folder for new text files that our clients drop off. It checks the folder every half second for files it hasn't seen before and when it detects a new file its gets processed.

    It works great for files under 20 KBs or so, but anything larger than that the program interferes and corrupts the file as it is being placed in the folder. Is there anyway for my program to not notice a file until after it has been completely loaded to the folder? Right now I am checking every half second for new files because the timer doesn't seem to work for anything larger than a second, I've done some research and figured out how to increase the time using scheduled events but that doesn't really solve the problem. I could have it check once an hour and there would still be that small chance that the client drops a file off at the exact time my program checks the folder.

    Here is the relavent code, workedFiles is a map to keep track of what files the script has seen before. The problem is definately this section, I've taken out all processing of files and the corruption and app crash still occurs:

    Java Code:
    public void actionPerformed( ActionEvent actionEvent) {
            File directory = new File(fileDirectory);
            String d[] = directory.list();
    
    
            for (int i=0; i<d.length; i++) {
                if (d[i].contains(".txt")) {
                    if (workedFiles.containsKey(d[i]) == false) {
                        workedFiles.put(d[i], new Integer(1));  // add file to hashmap
                        processFile(d[i]);   // still happens even if I comment this out
                    }
                }
            }
    }
    Last edited by pjyelton; 03-08-2009 at 06:46 PM.

  2. #2
    pjyelton is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default

    Nevermind, it looks like this might be an issue with the ftp folder I'm watching, not my program.

Similar Threads

  1. Accessing Sent Mail folder
    By extempore in forum Networking
    Replies: 1
    Last Post: 01-22-2009, 03:33 PM
  2. Replies: 0
    Last Post: 10-06-2008, 03:42 PM
  3. want to run my code from any folder ?
    By Shyam Singh in forum New To Java
    Replies: 1
    Last Post: 08-12-2008, 01:31 PM
  4. folder cloning
    By jad in forum Advanced Java
    Replies: 1
    Last Post: 07-01-2008, 12:28 AM
  5. add password to folder
    By ismailsaleh in forum AWT / Swing
    Replies: 1
    Last Post: 01-08-2008, 05:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •