The Artima Developer Community
Sponsored Link

Java Answers Forum
taking directory as a command line argument

2 replies on 1 page. Most recent reply: Oct 3, 2002 8:03 PM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
ravi veerla

Posts: 1
Nickname: raviteja
Registered: Sep, 2002

taking directory as a command line argument Posted: Sep 30, 2002 11:46 AM
Reply to this message Reply
Advertisement
hii everyone,
kindly help me with this. i have been trying to take directory path as a command line argument for a File based program. when i specify a directory name with spaces as a command line argument, the main(String[] args) takes them as a different argument after each blank space.
example: c:\documents and settings would be read as three different arguments.

i could write code to handle this situation but the solution is not generic. when i specify a directory name with more than one blank space in between,
example:
c:\documents<more than one space>and<more than one space>settings as my argument ... i fail.

is there anyway that i can read blank spaces from the command line or can i read a set of command line arguments in to one string with out missing the blank spaces.


bree vanoss

Posts: 9
Nickname: bree
Registered: Sep, 2002

Re: taking directory as a command line argument Posted: Sep 30, 2002 3:08 PM
Reply to this message Reply
I believe you simply wrap your argument in quotes.

-=bree

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: taking directory as a command line argument Posted: Oct 3, 2002 8:03 PM
Reply to this message Reply
Just enclosing the arguments with quotes will do it.

But you could concatenate the arguments with a space between them with some code like:


public static void main(String[]){
String filePath = "";
if (args.length > 1){
for (int i = 0; i < args.length; i++){
if (i = 0){
filePath = args[0];
}else{
filePath = filePath + " " + args[i];
}
}
}else{
filepath = args[0];
}

/* code to deal with filePath */
//******************
//*****etc...
}

Flat View: This topic has 2 replies on 1 page
Topic: Java in WinCE Previous Topic   Next Topic Topic: An Array of Test Entry Boxes

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use