• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

create folder on remote system

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to create folder on the remote system using java code....
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 28402
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Have you no shame? Have you no decency? Have you no tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic