Is there a way to know if a file is saved to a folder

B

brightlette

Masters,

I am new to Java language. Are there some kinds of FileSaved events
that I can catch? If yes, could you please show me how to write a
simple .java file to catch the event?

Thanks!
 
N

NullBock

There's no built-in functionality to do that. You'll simply have to
poll the files that you want to watch. Use a java.util.Timer to check
the file(s) every second or so. Something like:

class WatchFile {
File file;
Timer timer = new Timer();

WatchFile(File file) {
this.file = file;
timer.schedule(new TimerTask() { public void run() { check(); } },
0, 1000);
}
long lastModified;
private void check() {
long l = file.lastModified();
if (l != lastModified) {
lastModified = l;
fireFileChanged();
}
}

protected void fireFileChanged() {
//....
}
}

Hope this helps,

Walter
----
Walter Gildersleeve
Freiburg, Germany

"In science, 'fact' can only mean 'confirmed to such a degree that it
would be perverse to withhold provisional assent.' I suppose that
apples might start to rise tomorrow, but the possibility does not merit
equal time in physics classrooms." -- Stephen Jay Gould

______________________________________________________
http://linkfrog.net
URL Shortening
Free and easy, small and green.
 
C

Chris Smith

I am new to Java language. Are there some kinds of FileSaved events
that I can catch? If yes, could you please show me how to write a
simple .java file to catch the event?

No, there are not. You would need to write a background thread that
polls the directory listing and generates the event.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
A

Alun Harford

Masters,

I am new to Java language. Are there some kinds of FileSaved events
that I can catch? If yes, could you please show me how to write a
simple .java file to catch the event?

No, as such behavior is very OS specific.
Of cause, you could use JNI to run some native code, but that will limit you
to one platform.

Alun Harford
 
N

NullBock

You're kidding, right? You want to take the clean, system-independent
Java solution and replace it with a half-dozen native implementations?
I find that advice extremely dubious.

*Maybe* if you're rapidly polling a couple hundred unrelated files in a
time-sensitive operation. *Maybe* if it's meant for a single OS. In
any case, this isn't a task I'd wish on anyone.

Walter
----
Walter Gildersleeve
Freiburg, Germany

______________________________________________________
http://linkfrog.net
URL Shortening
Free and easy, small and green.
 
C

Chris Uppal

NullBock said:
You're kidding, right? You want to take the clean, system-independent
Java solution and replace it with a half-dozen native implementations?
I find that advice extremely dubious.

What are you talking about ? Chris's suggestion /is/ a "clean,
system-independent" Java solution.

-- chris
 
N

NullBock

What are you talking about, what am I talking about? I was responding
to Roedy's comment, not Chris's.

Walter

----
Walter Gildersleeve
Freiburg, Germany

______________________________________________________
http://linkfrog.net
URL Shortening
Free and easy, small and green.
 
C

Chris Uppal

NullBock said:
What are you talking about, what am I talking about? I was responding
to Roedy's comment, not Chris's.

Not here you weren't. Your post appeared here directly after (in thread order)
Chris's post. Since you didn't quote anything nor say who you were replying
to, the only possible conclusion was that you were replying to Chris.

Quoting in Usenet posts is /not/ an affectation -- it is necessary for clear
communication. Usenet etiquette has evolved in response to actual needs, it
should be followed. This applies to Google users too.

-- chris
 
N

NullBock

Yes, here I was. Get a decent newsreader--Outlook Express is crap.
Thunderbird is free, for God's sake.

Walter
 
C

Chris Uppal

NullBock said:
Yes, here I was. Get a decent newsreader--Outlook Express is crap.
Thunderbird is free, for God's sake.

It's not because of OE. Thunderbird (if I could stand its many flaws -- which
I can't) would show the same thing.

And no. It's not because I'm using a crap newserver either.

-- chris
 
W

Walter Gildersleeve

So now I've checked the thread in Outlook, Thunderbird *and* the Google
reader, and they all tell me I'm right. Maybe you should do your
research before replying.

----
Walter Gildersleeve
Freiburg, Germany

______________________________________________________
http://linkfrog.net
URL Shortening
Free and easy, small and green.
 
T

Timo Stamm

Chris said:
It's not because of OE. Thunderbird (if I could stand its many flaws -- which
I can't) would show the same thing.

And no. It's not because I'm using a crap newserver either.


I don't know what's gone wrong here, but Walter *did* reply to Roedy.


Here is are some headers of Roedys message:

From: Roedy Green <[email protected]>
Newsgroups: comp.lang.java.programmer
Subject: Re: Is there a way to know if a file is saved to a folder
Message-ID: <[email protected]>


Here is are some headers of Walters reply:

From: "NullBock" <[email protected]>
Newsgroups: comp.lang.java.programmer
Subject: Re: Is there a way to know if a file is saved to a folder
Message-ID: <[email protected]>
In-Reply-To: <[email protected]>


Note the In-Reply-To header, which clearly references Roedys message as
it's parent.


Timo
 
C

Chris Smith

NullBock said:
Yes, here I was. Get a decent newsreader--Outlook Express is crap.
Thunderbird is free, for God's sake.

This has nothing to do with Outlook Express. The problem is that you
aren't providing any context when you post, and this is confusing.
USENET is an imperfect world, and posts don't get propogated. I saw
Roedy's post, but apparently it didn't make it to Chris's server.
That's not Chris's fault, and your attitude is bizarre, to say the
least. If you followed reasonable USENET form by quoting a few lines of
attributed context before your reply, the problem would have been
obvious.

Unfortunately, you are posting through Google, which can make this hard.
That *is* a problem with your newsreader... but fortunately there is a
workaround. See http://cfaj.freeshell.org/google/

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
T

Thomas Weidenfeller

Timo said:
I don't know what's gone wrong here,

Probably nothing special. When Chris U. looked at IchBin's message, his
news server probably didn't have Roedy's message to which IchBin
replied. So Chris U.'s newsreader decided to display the thread without
Roedy's message. That made it look for Chris U. as if IchBin had replied
to Chris S., and not Roedy.

Usenet is a distributed, non-realtime system. So things like this
happen. Messages travel different pathes at different times, and
sometimes they never arrive. Quoting the relevant part of a posting is a
good idea.

Whether it is a good idea by a newsreader to display something like this
without some indication is up for debate (assuming this is what happened).
Note the In-Reply-To header, which clearly references Roedys message as
it's parent.

AFAIK its the "References:" header which links messages. Looking at
them, they also look OK in the postings.

/Thomas
 
T

Timo Stamm

Thomas said:
AFAIK its the "References:" header which links messages. Looking at
them, they also look OK in the postings.


The In-Reply-To header was set by Walter's newsreader. You can't trust
this information. But it would seem a bit odd to assume that Walter
deliberately set a wrong header, wouldn't it? He doesn't gain anything
from faking this information, and it is a clear indicator that he did
reply to Roedy.

Anyways, sensible quoting makes a thread much more readable and also
prevents such misunderstandings.


Timo
 
T

Thomas Weidenfeller

Timo said:
The In-Reply-To header was set by Walter's newsreader. You can't trust
this information. But it would seem a bit odd to assume that Walter
deliberately set a wrong header, wouldn't it? He doesn't gain anything
from faking this information, and it is a clear indicator that he did
reply to Roedy.

I am not saying anyone did anything wrong with any headers. I am saying:

The standard header which links together postings
is the "References:" header and not the "In-Reply-To:"
header.

Nothing more, nothing less.

I am also saying, with regards to the References headers (to quote myself):

How one can interpret this as an attack of Walter is beyond my
understanding.

/Thomas
 
L

Luc The Perverse

Thomas Weidenfeller said:
Probably nothing special. When Chris U. looked at IchBin's message, his
news server probably didn't have Roedy's message to which IchBin replied.
So Chris U.'s newsreader decided to display the thread without Roedy's
message. That made it look for Chris U. as if IchBin had replied to Chris
S., and not Roedy.

Usenet is a distributed, non-realtime system. So things like this happen.
Messages travel different pathes at different times, and sometimes they
never arrive. Quoting the relevant part of a posting is a good idea.

Whether it is a good idea by a newsreader to display something like this
without some indication is up for debate (assuming this is what happened).


AFAIK its the "References:" header which links messages. Looking at them,
they also look OK in the postings.

/Thomas

Which wouldn't have happened if NullBrain had quoted properly
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top