What is the recommended way of accessing a network share folder (located in Windows or Linux) in java

前端 未结 1 1754
一整个雨季
一整个雨季 2020-12-28 10:12

All, Forgive me I am not familiar with the Linux. I am trying to read all the files of a network share folder which is located in either Windows or Linux system.

Cu

相关标签:
1条回答
  • 2020-12-28 10:54

    Remote Mount with FUSE

    It's possible to mount a remote filesystem (generally including SMB/CIFS) with FUSE and samba. That might look something like (assuming you have a mountpoint /windows)

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

    Then you could 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 linked documentation for SmbFile does give the full format as

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

    and it also notes that all SMB URLs that represent workgroups, servers, shares, or directories require a trailing slash '/'.

    0 讨论(0)
提交回复
热议问题