• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create folder at runtime from client side in server in LAN Connection  RSS feed

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two computers connected in LAN lets say A and B, where A is server and B is client. I have created Java appln using that I want to create folder at A from B. In normal situation I used following code to create folder.



But this code does not work here. I tried to provide IP address in front of it.



But it gave me error.


The specified path, file is invalid.


Can you tell me guys how to create.
Thank you in advance.
 
Sanurag Dharme
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry guys I mistakenly created Post in different forum.
 
Sheriff
Posts: 11338
177
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanurag Dharme wrote:Sorry guys I mistakenly created Post in different forum.

No problem! I moved it to another (more appropriate) forum.
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, to access a folder on a remote folder using network shares, that folder must be actually shared. On Windows you often get that for free since all drives are shared out-of-the-box. Instead of D:, you need to use D$ (so replace the : with a $). If this doesn't work, you must create an explicit share.

That's not enough though. You also need to tell on which machine the share is located. This is done using \\machinename. In your case, the total path would become \\192.168.1.9\D$\ESM\Student. Next you need to escape all those backslashes if you need to create a string with that value. That indeed means the value will start with 4 backslashes in the code.

Note that you can also use forward slashes which you don't need to escape. I prefer those because it's clearer.
 
Sanurag Dharme
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still doesn't work.. I tried following code



and this also



and also this



but none this are working. Can you tell me whats wrong here.
 
Sanurag Dharme
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the solution. I map network drive of shared drive and pass its address and now its working.

 
Roel De Nijs
Sheriff
Posts: 11338
177
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanurag Dharme wrote:I map network drive of shared drive and pass its address and now its working.

And what will happen if someone runs this code who has mapped the address to drive X (or didn't have mapped the drive at all)?
 
Sanurag Dharme
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yes I didn't think of it, thanks for pointing out. But if these is not correct solution then can you tell me because previous didn't work out.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you have to provide credentials when you created the network mapping? If so then java.io.File won't be able to help you; it simply cannot handle shares that require you to login. you should check out JCIFS or a similar library instead.
 
Sanurag Dharme
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No don't need to provide credentials.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!