|
-
Feb 9th, 2004, 11:18 PM
#1
Thread Starter
Addicted Member
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
-
Feb 10th, 2004, 12:54 AM
#2
Dazed Member
You could use lastModified() which returns a long value which represents the time the file was modified.
-
Feb 10th, 2004, 12:57 AM
#3
Thread Starter
Addicted Member
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
-
Feb 10th, 2004, 01:11 AM
#4
Dazed Member
Polling implementation for sure.
-
Feb 10th, 2004, 01:41 AM
#5
Thread Starter
Addicted Member
Darn, I had a feeling you were gonna' say that. Thanks for your
input regardless!
-
Feb 10th, 2004, 03:05 AM
#6
Dazed Member
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");
}
}
-
Feb 10th, 2004, 04:51 AM
#7
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.
-
Feb 10th, 2004, 11:22 AM
#8
Thread Starter
Addicted Member
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?
-
Feb 10th, 2004, 12:04 PM
#9
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.
-
Feb 10th, 2004, 12:44 PM
#10
Thread Starter
Addicted Member
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.
-
Feb 10th, 2004, 01:05 PM
#11
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.
-
Feb 10th, 2004, 01:06 PM
#12
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|