java cli accepting file paths as parameters
ok, so one more stupid question and then Im done for a while.
I need to accept a path to a folder as one of the parameters on the cli. I _really_ dont want to write the bit that chops it up unixy style myself, is there some standard java way of handling that kind of input?
You want to chop up the args array or the path?
the path, Id like to allow for the standard wild cards and expansion behavior and so on. its not _absolutely_ necessary, so if its gonna be a mission Ill leave it, but it feels like a Nice Thing To Do.
I do believe that Java has a standard way of handling the path separators and forward/backward slashes.
No, I don't remember how it works, just that I think it does.
you would create a java.io.File (http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html
) from the String that's passed in and then use File's methods to access the different components of the path. Wildcards and stuff are usually handled by the shell if you're passing them in via cli and I'm not aware of any standard java libs for globbing etc.
ok, cool. thats what Im doing so I guess Ill leave it.
for some reason I had always assumed that the programs themselves were handling the expansion & wildcards, dunno why..silly now I think about it...
Is there a way to make File step through the components of a path? /usr/incude/crap/under/here ....
March 11th, 2007 4:20pm
you can step backwards using .parent and receiving a File with that file system object, if you want to do the other way though Im not sure how you would do it, except that it probably involves using the path separate provided by the File pbject and string manipulation.
Cocoa has some lovely builtin stuff for walking file paths in that way. ::sigh::