Results 1 to 12 of 12

Thread: File-system magic?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Middle Earth
    Posts
    156

    File-system magic?

    Folks, I have a conceptual problem that I can use some help on.
    Lets say I have an application that stores any kind of data file in
    a database. Said database entries would be represented visually
    to an end user. When double-clicking on any such entry, the will
    be downloaded to some temporary folder and 'executed' (i.e.
    whatever program is associated with the file will launch and
    load it).

    Would there be any reasonable way to check if a user has
    finished with the file, and if so if the file was changed (so it
    could be uploaded back to the db server as 'modified')?

    I considered timers and loops to do the job, but this sucks
    away alot of processing time unnecessarily. I also considered low
    level file system hooking (platform dependent code), but that
    defeats the benefits of java.

    So, any ideas / advice?

    -CC

  2. #2

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Middle Earth
    Posts
    156
    Thanks Dilinger,

    Would there be any way to reactively use this function to some
    event or would you forsee this as being a polling implementation?

    -CC

  4. #4

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Middle Earth
    Posts
    156
    Darn, I had a feeling you were gonna' say that. Thanks for your
    input regardless!

  6. #6
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    How far back do you want to check to see when the file was modified? Im not sure how accurate this is or my math for that matter.
    Code:
    
     import java.io.*;
     import java.util.Date;
     
     public class filetest{
       public static void main(String[] args){
    
       File f = new File("C:" + File.separator + "Test.txt");
       
       long currenttime = System.currentTimeMillis();
       long lastmodified  = f.lastModified(); 
        
       System.out.println(new Date(currenttime)); 
       System.out.println(new Date(lastmodified)); 
    
       howlongagomodified(currenttime, lastmodified);
     }
       public static void howlongagomodified(long currenttime, long lastmodified){
        //how long ago was the file modified?
    
        long l = currenttime - lastmodified;
        long secspast  = l / 1000;
        long minspast = secspast / 60; 
        long hourspast = minspast / 60; 
    
        System.out.println("File was modified: " + (minspast / 60) + " hours "
                 + (minspast % 60) +
                         " minutes ago");
        }
      }

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    How do you execute the editing app, anyway? You can use the Process object returned by Runtime.exec to check when the app exits. Then you check if the lastModified time has changed.

    That's what I'm doing, anyway.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Middle Earth
    Posts
    156
    Dilenger4,

    Thanks for the code. Alghough it doesn't seem to address my
    main concern (an automatic trigger for when a temp file has
    been modified), it is certainly a nice starter.


    CornedBee,

    I actually have not chosen an implementation yet. I would
    probably just 'execute the file' and see what the OS did with
    it (ex. in Windows the natural association may link it up
    with the appropriate app).

    I guess an alternative idea may be to keep track of the application
    association within MY application and then use the process
    object to launch the app with the file being a parameter. Perhaps
    I could then respond to the termination of the process with some
    kind of exception handler that would in turn check the file data
    and re-upload the file to the database if it had changed. What
    do you think?

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I know that using Runtime.exec fails if the file is not a real executable. You can't exec data files.

    I wrote a JNI class that executes the stuff. The computer it is on is currently out of order though.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Middle Earth
    Posts
    156
    Darn... well it looks like I have another problem to push on the
    stack. I do however want to stay away from JNI in this case, but
    I think it's cool that you found a JNI solution.

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I can give you my JNI stuff once I get it back. Works on Windows, but I need to write a Linux implementation.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    Middle Earth
    Posts
    156
    Thanks CB

Posting Permissions

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



Click Here to Expand Forum to Full Width