Results 1 to 12 of 12
Thread: Args[0]
- 12-03-2009, 11:13 AM #1
Member
- Join Date
- Nov 2009
- Posts
- 13
- Rep Power
- 0
Args[0]
Hello All!
I am new to Java. I run my java binary from command prompt, where i can run it with a file name, or with the full path of the file(it contains filename in the end). now i want to check whether the argument passed is just a filename or it is the fullpath.if it is the full path(and file name in the end), i want to read the filename from it,
please help me.
thanks
- 12-03-2009, 11:24 AM #2
So, if it contains one or more / or \ you've got a full path with maybe a filemane at the end, but you'd still have to check whether 3:/fff/barf/foo.bar/barf is a valid path to a file or just garbage.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 12-03-2009, 12:33 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 13
- Rep Power
- 0
Thanks!
Thenks Phein!
but still i did not get how i would be able to do it. and let us suppose that in my case the argument is always a valid path(if it is not a filename).
- 12-03-2009, 12:39 PM #4
You could create a File object from the parameter and use the exists() method to find out whether the file is in your file system. If it is there you've got a valid path to a file.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 12-03-2009, 12:48 PM #5
Member
- Join Date
- Nov 2009
- Posts
- 13
- Rep Power
- 0
Thanks!
thanks phein for your reply. but that is what i want. I want to retreive the Filename from the path(if the input argument in a path instid of file)
- 12-03-2009, 12:50 PM #6
Then split the argument, the last token is your file name.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 12-03-2009, 01:04 PM #7
Member
- Join Date
- Nov 2009
- Posts
- 13
- Rep Power
- 0
thanks Phein!
but i wonder if i split my argument, then the last token will be my filename:this will be valid for the case when the argument passed will be a path. my question: if i use split string, will it work in the case when arguemnt is filename???
- 12-03-2009, 01:17 PM #8
Yes it will, why don't you just try it?
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 12-03-2009, 01:18 PM #9
Oh, and another one both these are paths:
c:/foo/doc.doc
c:\foo\doc.docMath problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 12-03-2009, 04:39 PM #10
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
args[0].replace("\\","/") will solve that phhein :)
- 12-03-2009, 04:41 PM #11
I know that, but I wanted to give hakan123 a chance to do some research and to learn something new instead of spoon feeding him.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 12-03-2009, 05:40 PM #12
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
Similar Threads
-
What does String args[] stand for?
By Addez in forum New To JavaReplies: 7Last Post: 08-19-2009, 10:24 AM -
How to add Args at runtime in JCreator
By JordashTalon in forum JCreatorReplies: 0Last Post: 01-28-2009, 10:12 PM -
Why can't we write main without String args[]
By shailender in forum New To JavaReplies: 4Last Post: 11-05-2008, 10:58 AM -
problem in args
By MS_Dark in forum New To JavaReplies: 13Last Post: 08-27-2008, 01:43 AM -
command line args
By MarkWilson in forum NetBeansReplies: 3Last Post: 08-04-2008, 03:22 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks