在java中访问网络共享文件夹(位于Windows或Linux中)的推荐方法是什么? [英] What is the recommended way of accessing a network share folder (located in Windows or Linux) in java

查看:1151
本文介绍了在java中访问网络共享文件夹(位于Windows或Linux中)的推荐方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,原谅我,我不熟悉Linux。
我正在尝试读取位于Windows或Linux系统中的网络共享文件夹的所有文件。

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.

目前我刚刚为它工作了以下代码的Windows案例。

Currently I just made it work for the case of Windows by below code.

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

但是当我将我的应用程序部署到Linux系统并运行它时。它只是告诉我无法从指定的 networkShareFolder ;

But When I deploy my application to the Linux system and run it. It just told me can not get any files from the specified networkShareFolder;

获取任何文件所以我尝试输入路径< Linux中的文件浏览器中的code> \\10.50.90.18 就像我在Windows中所做的那样。查看是否可以从Linux系统访问该路径。但它只是告诉我无法找到\\10.50.90.18 。但我确信IP可以从Linux ping。

So I tried to type the path \\10.50.90.18 in the File explorer of Linux like what I did in the windows. To see if the path can be reached from the Linux system. But it just told me Can't locate the \\10.50.90.18. But I am sure the IP can be ping from the Linux.

所以我的问题是


  1. 为什么 \ \ 10.50.90.18 无法在Linux中访问。但可以在Windows中访问。 (我相信他们的IP都是10.50.90。*)

  2. 从windows或linux访问网络共享文件夹的最佳方法是什么?

  1. Why \\10.50.90.18 can't be accessed in Linux .But can be accessed in Windows. (I am sure their IP are all 10.50.90.*)
  2. What is the best way to access the network share folder from windows or linux ?

谢谢。

推荐答案

使用FUSE进行远程安装



使用 FUSE

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

然后您可以使用

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



Pure Java Solution(with JCIFS)



JCIFS 提供 SmbFile 提供 listFiles( ) 允许类似

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();

SmbFile 的链接文档确实给出了完整格式为

The linked documentation for SmbFile does give the full format as


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

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

和它还指出代表工作组,服务器,共享或目录的所有SMB URL都需要一个斜杠'/'。

这篇关于在java中访问网络共享文件夹(位于Windows或Linux中)的推荐方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆