Java 在共享位置打开文件 [英] Java open file on shared location

查看:25
本文介绍了Java 在共享位置打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做这样的事情:

File root = new File("C:/file.txt");

File root = new File("C:/file.txt");

但是在本地网络上共享的文件夹上.那么让我们说文件在 192.168.1.28 上如何使用上述命令制作它?

but on a folder which is shared on a local network. So lets say the file is on 192.168.1.28 how make it with above command?

下一步不工作:

File root = new File("//192.168.1.2/file.txt");

File root = new File("\\\\192.168.1.2/file.txt");

File root = new File("\\192.168.1.2/file.txt");

File root = new File("file:\\192.168.1.2/file.txt");

File root = new File("file://192.168.1.2/file.txt");

非常感谢.

推荐答案

您可以使用 Apache Commons VFS.它是一个允许您操作各种文件系统上的文件的库,CIFS 文件系统就是其中之一:

You can use Apache Commons VFS. It is a library that allow you to manipulate files on various kind of filesystem, one of them perfectly suited for your need is the CIFS file system:

提供对 CIFS 服务器(例如 Samba 服务器)上文件的访问权限,或 Windows 共享.

Provides access to the files on a CIFS server, such as a Samba server, or a Windows share.

URI 格式

smb://[用户名[:密码]@]主机名[:端口][绝对路径]

smb://[ username[: password]@] hostname[: port][ absolute-path]

示例

smb://somehost/home

CIFS 文件系统的提供程序仍在开发中,但您可以尝试一下.我已经使用该库通过 http 和 ftp 协议提供对文件的透明访问.

The provider for CIFS file system is still in development, but you can give it a try. I've already used the library to give transparent access to files via http and ftp protocols.

这篇关于Java 在共享位置打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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