[英]Virtual filesystem mapping to local file
How can I decorate some remote filesystem like a path to directory in java? 如何装饰一些远程文件系统,例如Java中的目录路径? For example something like this: 例如这样的事情:
File decoratorFileSystem = new File("ftp://host/path"); // this does not work of course
...
File file1 = new File(decoratorFileSystem, "somefile1");
File file2 = new File(decoratorFileSystem, "somefile2");
So when I will use file1
, file2
or others decorated files I get access to remote file from the decorated filesystem as if it local file with corresponded restrictions. 因此,当我将使用file1
, file2
或其他修饰的文件时,可以从修饰的文件系统访问远程文件,就好像它是具有相应限制的本地文件一样。
I think to use virtual file system from "org.apache.commons.vfs2.provider...." but I am not sure is this right way... 我认为要使用“ org.apache.commons.vfs2.provider ....”中的虚拟文件系统,但是我不确定这是正确的方法...
A File
in Java can only ever reference a real file on a filesystem mounted by the OS (ie something that the OS knows to be a file). Java中的File
只能引用OS挂载的文件系统上的真实文件(即OS知道是文件的东西)。
Virtual filesystems can't be accessed this way (unless it's handled by the OS, ie if you mount a FTP directory directly under Linux, you can use a File
). 无法通过这种方式访问虚拟文件系统(除非它由操作系统处理,即,如果直接在Linux下安装FTP目录,则可以使用File
)。
The newer Path
class from NIO2 (available in Java 7 and later) however was explicitly designed with virtual file systems in mind. 但是,NIO2中较新的Path
类 (在Java 7和更高版本中可用)在设计时明确考虑了虚拟文件系统。
Look at this tutorial and the FileSystemProvider
class to find out how to define your own virtual file system. 查看本教程和FileSystemProvider
类,以了解如何定义自己的虚拟文件系统。 The Zip File System Provider is a sample implementation. Zip文件系统提供程序是一个示例实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.