permaculture playing cards*
The moose likes Other JSE/JEE APIs and the fly likes File System Events [JNI] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "File System Events [JNI]" Watch "File System Events [JNI]" New topic
Author

File System Events [JNI]

Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Hi all,
I want to write a program that interacts with the file system, or rather with the events I suspect the file system raises when such things like a file is moved, or a new file created.

I know the basic form will be to have a system library that captures the events, and then via JNI "throws" them up to a java layer, where any processing can take place.

I was just wondering, as this strikes me as something a lot of people would want to do, is this already part of JNI, or will I have to learn to do some MFC programming in windows? (As my first target platform).

I would rather avoid writing windows code if possible, although, I can code in C# perhaps this would shield me from the horridness of C++/MFC.

Thanks
G
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

Nothing is a part of JNI. JNI merely allows Java code to call on native shared libraries.
I believe "MFC" refers more to the GUI programming library than file system routines. When I last did native stuff on Windows, the file system routines were in the Win32 API. The same functionality may be offered in .NET, so you may be able to get by with C#.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Sorry for my bad use of technical terms.

Thanks, I was hopeing that wouldnt be the answer, i was hopeing that Java had an API for working with FileSystem events, but then I guess if they provide one for the FileSystem, then other sub-systems of the OS will be demanded.

G
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

Originally posted by Gavin Tranter:
Sorry for my bad use of technical terms.


We're all here to learn. And I could be wrong. My statements are based on my best memory of work I did years ago.
You have to remember that Java is platform independent. File systems vary widely, even on a particular platform (Windows has FAT, FAT32, NTFS; *nix has several ext's, several Reiser's, xfs, zfs and many, many more). Sun took care of most of the common features and left the rest to the programmer.
If all you are concerned about is watching a directory for new, changed and deleted files, do a search in the "Java In General" forums here. Lots of people have implemented similar things using a thread and the java.io.File class.
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Hi,
Yeah I understand that, but my use of JNI was rather broad and off the mark really, mad all the worse as I know what JNI is and have used it in the past. As to MFC well I just remember it as the class library to use to develop Windows application, that wasnt as well put together as OWL and in general to be avoid (Generally i think the writing of Windows apps outside of soemthing like delphi was to be avoided).

Yeah I dont really think the thread method is inappropriate as I want to "watch" the whole file system.

Basicly I am sick of the current file mangers you get with windows (not sure about vista, I dont want to even look at vista), so I want to write one that works the way I work.

I have found some code under the apache license (here) which looks like it does what I want.

Also .Net has a FileWatcherControl, but JNI for using C# looks like a nightmare, creating managed code to that the C# calls that then calls the JNI layer.

I will have a look at the above code and post results if anyway, I have several projects and no time
Timothy Wall
Greenhorn

Joined: Sep 14, 2002
Posts: 14
The JNA project includes some demo code which uses the w32 file system API to report file system changes. You don't have to write any native code, but you may need to tweak the java if the class doesn't do exactly what you want it to already.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

"As to MFC well I just remember it as the class library to use to develop Windows application, that wasnt as well put together as OWL and in general to be avoid (Generally i think the writing of Windows apps outside of soemthing like delphi was to be avoided)."

Who told you that - I bet it was someone from Borland (who were selling their own compiler with the OWL library and who were selling Delphi)... :roll: MFC (Microsoft Foundation Classes) is Microsoft's object oriented library to write C++ applications for Windows. Yes, Borland will tell you it is "to be avoided" because they want you to use their tools instead of Microsoft's...


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Hey not had a chance to look at JNA.

Well the whole OWL thing was down to reading several articals of the time that came out in favour of OWL being somewhat better put together, and more logically organised then MFC. I could be wrong, but I also got the impression at the time OWL existed before MFC came along.
Admittedly I was more likley to such articals as I prefered, and still prefer Borland compilors over MS ones (Along with their associated IDE's).

As to avoiding programming windows apps outside of something like delphi, you obivously missed that it was a personaly opinion, and that I said something like delphi, this would include VB, and to a lesser degree C++ Builder and an even lesser degree VC++. I am sure there were other visual tools of the time, but for my money, Delphi was the one to chose, it was object orinetated, and a compiled language, unlike VB. (Which didnt get decent object support until about version 6, was based on basic, and required a runtime library, and we all know what BASIC stands for).

I will get back to JNA just as soon as i get 5minutes to myself. It is probably exactly what I am looking for, I just want to know when a file is added, deleted, or moved. I want to write a file manager application, as I am sick of having to fight with teh current crops I want one that works like I do. Also I am hopeing it will be easier for non techies, but thats for another day.

G
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File System Events [JNI]
 
Similar Threads
Get Serial number of exernal hard disk/Thumbdrive using java code &work for both linux and windows
what is JNI and what are the advantages of JNI?
Use a .dll file.
How to create shortcut for a file using JAVA
J2SE OS for iPaq