• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Map network drive in java

 
Aruna Jayabalu
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20399
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add double quotes around the path.
 
Aruna Jayabalu
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 256
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
\\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
Posts: 256
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20399
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you really have to put the quotes around the entire path, including the server name, as Aruna has already found out.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic