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

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

问题描述

我想做这样的事情:

文件根=新文件("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?

下一个无效:

文件根=新文件("//192.168.1.2/file.txt");

文件根=新文件("\\\\ 192.168.1.2/file.txt");

文件根=新文件("\\ 192.168.1.2/file.txt");

文件根=新文件(文件:\\ 192.168.1.2/file.txt");

文件根=新文件("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天全站免登陆