| Author |
Map network drive in java
|
Aruna Jayabalu
Greenhorn
Joined: Aug 09, 2011
Posts: 12
|
|
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: 19216
|
|
|
Add double quotes around the path.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Aruna Jayabalu
Greenhorn
Joined: Aug 09, 2011
Posts: 12
|
|
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: 12
|
|
\\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: 19216
|
|
|
No, you really have to put the quotes around the entire path, including the server name, as Aruna has already found out.
|
 |
 |
|
|
subject: Map network drive in java
|
|
|