In the recent versions of windows, you can hit the start menu and start typing to search for files across the filesystem. Is there a way to do that programmatically in Java?
My specific purpose is to allow the user to choose a file o开发者_JAVA百科r directory. The user could start typing a file name directly inside the application and it could start showing suggestions. Much easier than navigating directories in a typical file chooser.
This post details a way to do this in Windows, by accessing the native functionality:
Query Windows Search from Java
And this one details how you can do something similar (using mdfind
) under Mac OS:
http://lists.apple.com/archives/Java-dev/2006/Oct/msg00224.html
What you're asking for in the second part of your question could be done with a simple:
File dir = new File( "/path/to/dir" );
String[] contents = dir.listFiles();
The first part is a bit harder, but it could be accomplished inside Java using the same technique called recursively. (for(String fl: contents){ /* do the above */ })
You don't want to worry about supporting wrappers around command line calls here. That is anti-platform independent.
you could write JNI code to wrap+expose any windows native functionality.
If it's just for autocomplete style behavior in a file dialog, you don't need to wrap the native functionality, you can just use standard stuff in java.io.
Sounds unlikely ti be a part of Java, since Java is supposed to be platform-independent. Such searches should require some sort of index over all files, to be efficient, also.
精彩评论