What is the recommended way to access a shared network folder (located on Windows or Linux) in java

Forgive me, I am not familiar with Linux. I am trying to read all the shared folder files that are on a Windows or Linux system.

Currently, I just did it for Windows in the case of code below.

networkShareFolder="\\\\10.50.90.18\\ITS Tool\\xml\\";//It is a windows Network share path. File[] files = new File(networkShareFolder).listFiles(); 

But when I deploy my application on a Linux system and run it. He just told me that he could not get the files from the specified networkShareFolder ;

So I tried to enter the path \\10.50.90.18 in File Explorer Linux, like what I did on Windows. To find out if a path can be reached from a Linux system. But he just told me Can't locate the \\10.50.90.18 . But I'm sure IP can be ping from Linux.

So my questions

  • Why \\10.50.90.18 not available on Linux. But access to them is possible in Windows. (I am sure that their IP is all 10.50.90. *)
  • What is the best way to access a shared folder from windows or Linux?

Thanks.

+5
source share
1 answer

Remote installation with fuse

It is possible to mount a remote file system (usually including SMB / CIFS) with FUSE and samba . It might look something like this (if you have a mount point /windows )

 # export USER=efrisch # export WORKGRP=mygrp # smbmount //10.50.90.18/ /windows –o username=$USER,workgroup=$WORKGRP 

Then you can access your directory (transparently) with

 new File("/windows/ITS Tool/xml") 

Pure Java solution (with JCIFS)

JCIFS provides SmbFile and that provides listFiles() , allowing something like

 SmbFile[] files = new SmbFile("smb://10.50.90.18/ITS Tool/xml/").listFiles(); 

The related documentation for SmbFile gives the full format as

SMB: // [[[domain]; username [: password] @] server [: port] / [[share / [dir /] file]]]? [PARAM = value [param2 = value2 [...]]]

and also notes that all SMB URLs representing workgroups, servers, folders, or directories require an end slash '/'.

+10
source

All Articles