aspose file tools
The moose likes Java in General and the fly likes Map network drive in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Map network drive in java" Watch "Map network drive in java" New topic
Author

Map network drive in java

Aruna Jayabalu
Greenhorn

Joined: Aug 09, 2011
Posts: 13
Hi all,

I was trying to map a remote ip to my machine in a java program..

String command= "net use K: \\\\10.234.34..\\test\\ /USER:username password";
Process output = Runtime.getRuntime().exec(command);

The above code works perfectly.
But the below command does'nt work. That's because of the space in the folder name.
String command= "net use K: \\\\10.234.34..\\test folder\\ /USER:username password";

Can you please suggest any solution for the above problem?

Thanks,
Aruna.J
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19950
    
  25

Add double quotes around the path.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Aruna Jayabalu
Greenhorn

Joined: Aug 09, 2011
Posts: 13
Hi,

Command is a String.. So its already enclosed within double quotes...
Even though meaning less, I even tried like this

String command= "net use K: \\\\10.234.34..\\"+"test folder"+ /USER:username password";
But no luck...
Have I understood your suggestion correctly?

Thanks,
Aruna.J

bhanu chowdary
Ranch Hand

Joined: Mar 09, 2010
Posts: 256
Aruna Jayabalu wrote:
String command= "net use K: \\\\10.234.34..\\"+"test folder"+ /USER:username password";


Try this
String command= "net use K: \\\\10.234.34..\\"+"\"test folder\""+ /USER:username password";

As Rob mentioned double quotes around the whole path will be good.
Aruna Jayabalu
Greenhorn

Joined: Aug 09, 2011
Posts: 13
\\10.234.34..\\"test folder"
dint not work..

But quotes for the entire path worked!!!

"\\10.234.34..\\test folder"


Thanks a lot!!!
bhanu chowdary
Ranch Hand

Joined: Mar 09, 2010
Posts: 256
Aruna Jayabalu wrote:\\10.234.34..\\"test folder"
dint not work..


I guess here you forgot to escape the last double-quote.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19950
    
  25

No, you really have to put the quotes around the entire path, including the server name, as Aruna has already found out.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Map network drive in java