Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will this work on Unix?

This Java code lists files in a directory on a Windows shared drive. Will it work correctly on a Unix system?

File directory = new File("\\\\server/Shared/stuff/mystuff");
for (File file: directory.listFiles()) {
    System.out.println(file);
}
like image 841
PiperTerry Avatar asked Jun 23 '10 17:06

PiperTerry


People also ask

Is Linux and Unix same?

Linux is a Unix clone,behaves like Unix but doesn't contain its code. Unix contain a completely different coding developed by AT&T Labs. Linux is just the kernel. Unix is a complete package of Operating system.

Is Unix used anymore?

However, Unix is still the preferred system for many use cases, such as data center application support, cloud security and vertical-specific software. Future Unix server sales are expected to drop, but applications in financial, government and telecommunications should continue to drive Unix use.


2 Answers

Short answer: No.

Long answer: Do you have samba installed? Even then you need to mount the the share. So it probably won't work.

EDIT

Java delegates the call to the underlying OS eventually. Since Unix doesn't know what the \\SERVERNAME path means, Java doesn't know what it means either. What you have to do, to get this to work is mount the drive explicitly using Samba. Your other option, if you are running Ubuntu, is look under .gvfs in your home directory. Ubuntu creates a mount there for your Samba shares, which you should be able to access using Java. If you don't want to rely on external tools, try JCIFS for a pure-Java solution.

like image 177
Vivin Paliath Avatar answered Oct 18 '22 22:10

Vivin Paliath


No... Just let the user select the right path and use an OS dependent file-selection dialog.

like image 42
rabbit Avatar answered Oct 18 '22 20:10

rabbit