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);
}
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.
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.
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.
No... Just let the user select the right path and use an OS dependent file-selection dialog.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With