aspose file tools*
The moose likes I/O and Streams and the fly likes How to access a shared folder on Windows system from Java application on Unix Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to access a shared folder on Windows system from Java application on Unix" Watch "How to access a shared folder on Windows system from Java application on Unix" New topic
Author

How to access a shared folder on Windows system from Java application on Unix

Nikhil Sun
Ranch Hand

Joined: Nov 13, 2005
Posts: 108
Hi Friends,

I am working on a Java application that accesses a shared folder on a Windows system.For example in my Java code I access a file called 'myfile.txt' contained in a shared folder called 'common'.
So in my code I give the folder path as:
\\common\\myfile.txt
Now I have created a jar out of this application and deployed it on Solaris system.But it obviously isn't working because Solaris system isn't able to access the 'common' folder.
How do you do this?What change is required for Java code on Unix to be able to access shared folder on Windows machine?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
The jCIFS library can be used to access Windows Shared directories. Its API mimics the File and File[In|Out]putStream classes in java.io, so you can pick it up very quickly.


Ping & DNS - updated with new look and Ping home screen widget
Vilmantas Baranauskas
Ranch Hand

Joined: Dec 20, 2006
Posts: 89
No change is required in Java code.

In your example you access a normal file system file "\\common\\myfile.txt". This is normal file like "c:\\myfile.txt". Java doesn't know it is shared, it thinks it is just a file.

On unix, file system is a little bit different. It is possible to mount shared folder "\\common\" on a local directory using SAMBA. E.g. you mount "\\common\" to "/mnt/common/" and then load file "/mnt/common/myfile.txt" from your java app.

http://en.wikipedia.org/wiki/Samba_software


Author of <a href="http://www.newsinjector.com" target="_blank" rel="nofollow">NewsInjector</a>
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

Originally posted by Vilmantas Baranauskas:
In your example you access a normal file system file "\\common\\myfile.txt". This is normal file like "c:\\myfile.txt". Java doesn't know it is shared, it thinks it is just a file.

You should use "\\\\common\\myfile.txt", since you also need to escape the first two \s.

Sometimes I miss that in Java - the raw string like Python has it. No need for escaping anything in those.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to access a shared folder on Windows system from Java application on Unix
 
Similar Threads
How to build a shared library for JNI
Folder sharing in Unix
Logging Folder access
Map drive access through Java Application running as a service
Urgent -- help please.. mapping unix project folder in JDeveloper