• Post Reply Bookmark Topic Watch Topic
  • New Topic

create folder on remote system  RSS feed

 
vara prasad
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to create folder on the remote system using java code....
 
Mittal Vishal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To create a directory on remote machine you should have Read/Write access on the directory inside which you are going to create the directory

FolderName=<Path of remote machine's Directory>\<folder you want to create>

File defaultDir = new File(FolderName);
defaultDir.mkdir();
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the appropriate part of the remote system's filesystem is being made available to remote clients (via SMB, NFS, AFP etc.), with permission for the user running the Java code to write to it, then you can just use normal Java File operations like File.mkdir(). Of course, you need to use the right file path syntax; that's nothing to do with Java, but is a function of the operating system and the type of remote filesystem (SMB, NFS etc.)

If the part of the remote system's filesystem is not made available, then you cannot directly write to it with Java or with anything else ... thank goodness! In that situation, you would need to get the user of the remote system to agree to install a program of yours that would communicate with your server via the means of your choosing (sockets, RMI, CORBA, SOAP etc.). That program could do things like creating directories, in response to commands over the network from your server.
 
vara prasad
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok now ,like if i want to create a folder on local system i will give path like
File file=new File("C:\\folderpath");

But if have to create folder on remote system ,how to give the file path

File file=new File("10.112.32.122\\c:\\filepath"); ??? something like this
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like Peter said, you can't access files on other people's machines unless they have published some sort of file share via NFS, CIFS/SMB (also known as Windows Networking) or something like that.

IF, however, the machine named "JOESMITH" has decided to share out a directory named C:\MYSHARE, you can access is using Windows Networking - providing your machine can use that protocol. The filename would be in UNC form, so the best way would be like this:

File file=new File("//JOESMITH/MYSHARE/adirectory/myfile.dat");

Note that UNC names don't have drive letters in them, since drive letters are assigned relative to the client machine. Instead you use the machine ID and published sharename. You CAN use an IP address for the machine name, but since the machine name is more meaningful, I recommend you use it.

Also, you may have noticed that I used "real" slashes instead of backslashes. I recommend doing that, since it's more portable - and because since a backslash is also a Java escape character, you can make typing mistakes that can be hard to debug.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!