Java Forum / General / February 2006
Is there a way to know if a file is saved to a folder
brightlette@yahoo.com - 14 Feb 2006 14:44 GMT 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!
NullBock - 14 Feb 2006 15:00 GMT 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.
Chris Smith - 14 Feb 2006 15:24 GMT > 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.
 Signature www.designacourse.com The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation
Roedy Green - 14 Feb 2006 18:56 GMT >No, there are not. You would need to write a background thread that >polls the directory listing and generates the event. To do it efficiently requires native OS hooks.
see http://mindprod.com/projects/filefinder.html
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
NullBock - 14 Feb 2006 20:31 GMT 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.
Roedy Green - 15 Feb 2006 01:27 GMT >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. see http://mindprod.com/projects/filefinder.html#WHYJNI
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Chris Uppal - 15 Feb 2006 09:31 GMT > 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
NullBock - 15 Feb 2006 12:03 GMT 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.
Chris Uppal - 15 Feb 2006 12:20 GMT > 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
NullBock - 15 Feb 2006 12:38 GMT Yes, here I was. Get a decent newsreader--Outlook Express is crap. Thunderbird is free, for God's sake.
Walter
Chris Uppal - 15 Feb 2006 14:12 GMT > 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
Walter Gildersleeve - 15 Feb 2006 15:15 GMT 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.
Timo Stamm - 15 Feb 2006 15:23 GMT Chris Uppal schrieb:
>> Yes, here I was. Get a decent newsreader--Outlook Express is crap. >> Thunderbird is free, for God's sake. [quoted text clipped - 3 lines] > > 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 <my_email_is_posted_on_my_website@munged.invalid> Newsgroups: comp.lang.java.programmer Subject: Re: Is there a way to know if a file is saved to a folder Message-ID: <ts94v15ro3es8q2p1d3kc2jsdh8np25c57@4ax.com>
Here is are some headers of Walters reply:
From: "NullBock" <loyal_caper@easypeas.net> Newsgroups: comp.lang.java.programmer Subject: Re: Is there a way to know if a file is saved to a folder Message-ID: <1139949070.517725.299730@f14g2000cwb.googlegroups.com> In-Reply-To: <ts94v15ro3es8q2p1d3kc2jsdh8np25c57@4ax.com>
Note the In-Reply-To header, which clearly references Roedys message as it's parent.
Timo
Thomas Weidenfeller - 15 Feb 2006 16:11 GMT > 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
 Signature The comp.lang.java.gui FAQ: ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
Timo Stamm - 15 Feb 2006 16:42 GMT Thomas Weidenfeller schrieb:
> 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
Thomas Weidenfeller - 15 Feb 2006 18:35 GMT > Thomas Weidenfeller schrieb: >> AFAIK its the "References:" header which links messages. Looking at [quoted text clipped - 5 lines] > 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):
>> they also look OK in the postings. How one can interpret this as an attack of Walter is beyond my understanding.
/Thomas
 Signature The comp.lang.java.gui FAQ: ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
Timo Stamm - 15 Feb 2006 20:43 GMT Thomas Weidenfeller schrieb:
> I am not saying anyone did anything wrong with any headers. I know.
> How one can interpret this as an attack of Walter is beyond my > understanding. I did not.
Yet another misunderstanding :(
Timo
Luc The Perverse - 15 Feb 2006 20:39 GMT >> I don't know what's gone wrong here, > [quoted text clipped - 18 lines] > > /Thomas Which wouldn't have happened if NullBrain had quoted properly
-- LTP
:) Chris Uppal - 16 Feb 2006 10:38 GMT > Here is are some headers of Roedys message: Thanks for the research. The problem was never that "broken" OE mislinked NullBlock's post, but that -- since Roedy's post wasn't there to link to -- it had to put it in the tree in the nearest available spot (I don't know what algorithm it uses).
The thing that NullBlock (aka Walter, unless -- as I'm tempted to do -- we adopt Luc's proposed nickname) doesn't understand... No, let me rephrase that, /one/ of the things NullBlock doesn't understand, is the nature of Usenet where many things, both accidental and deliberate, can prevent messages being viewed in any given client.
Cheers.
-- chris
Chris Smith - 15 Feb 2006 15:37 GMT > 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/
 Signature www.designacourse.com The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation
Luc The Perverse - 15 Feb 2006 20:47 GMT > Yes, here I was. Get a decent newsreader--Outlook Express is crap. > Thunderbird is free, for God's sake. Oh my god. It's another one of those "I know more than you cause I'm 1337 and you sux" a.sholes. You can't reason with it.
It's people like this that make me understand why some Muslims' mentality to chop off people's heads and ask questions later. (Disclaimer: I realize this does not apply to all Muslims - and I don't have a sword, so don't call the cops or anything.)
I think I'm going to develop a knee jerk plonk reaction - when someone refuses to quote because they know more than the people who have posted thousands of times. Plonk! <evil laugh>
-- LTP
:) NullBock - 16 Feb 2006 08:01 GMT You wound me cruely, sir, you do.
I, virginal in my innocence, pure as the driven snow. Slighted wrongfully, wounded to the heart and left bleeding, to die.
And anyway, my penis is bigger than yours.
Walter
Chris Smith - 16 Feb 2006 08:11 GMT > You wound me cruely, sir, you do. Who? In case you missed it the first time, http://cfaj.freeshell.org/google/
 Signature www.designacourse.com The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation
NullBock - 16 Feb 2006 08:31 GMT Didn't you see Luc's post? I'm 1337, so I don't do that. Hell, I'm 1338, if not more! You got nothing on me.
Walter
> Chris Smith <cdsmith@twu.net> said: > In Java, there's really no such thing as a destructor of course, but as > a near parallel, no matter how much delegation you do in your > constructors, users expect to only have to call a close() method once. > I don't see how that would create a problem, assuming you understand and > design for delegation of constructors. Luc The Perverse - 16 Feb 2006 11:25 GMT > Didn't you see Luc's post? I'm 1337, so I don't do that. Hell, I'm > 1338, if not more! You got nothing on me. > > Walter Wow you quoted! WTG
Now for the issue of top posting. . .
-- LTP
:) NullBock - 16 Feb 2006 11:55 GMT Heeeyyyy....I though you plonked me! I don't like you anymore.
Walter
> George Bush said: > BUSH: Mr. Speaker, Vice President Cheney, members of [quoted text clipped - 6 lines] > the husband who was taken so long ago, and we are grateful > for the good life of Coretta Scott King. (APPLAUSE)
BUSH: Every time I'm invited to this rostrum, I am humbled by the
> privilege and mindful of the history we have seen together. We > have gathered under this Capitol dome in moments of national [quoted text clipped - 8 lines] > allowed to harden into anger. > <snip> Luc The Perverse - 16 Feb 2006 11:25 GMT > You wound me cruely, sir, you do. > > I, virginal in my innocence, pure as the driven snow. Slighted > wrongfully, wounded to the heart and left bleeding, to die. Dude . . . it's ok.
> And anyway, my penis is bigger than yours. . . .
-- LTP
:) cristianosadun@hotmail.com - 22 Feb 2006 12:08 GMT It could be overkill, but you might have a look at
http://jpoller.sourceforge.net
Alun Harford - 14 Feb 2006 15:47 GMT > 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
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|