简体   繁体   English

虚拟文件系统映射到本地文件

[英]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. 因此,当我将使用file1file2或其他修饰的文件时,可以从修饰的文件系统访问远程文件,就好像它是具有相应限制的本地文件一样。

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.

相关问题 读取使用虚拟文件系统JIMFS创建的文件 - Reading a file created using virtual filesystem JIMFS Java将文件从虚拟文件系统附加到电子邮件 - java attach file from virtual filesystem to email 使用hadoop FileSystem从本地文件系统中的jar文件读取 - Reading from jar file in local filesystem using hadoop FileSystem 来自本地文件系统的Ap​​ache httpclient GET文件? - Apache httpclient GET file from local filesystem? Maven:在本地文件系统上打包Jar,但不在WAR文件中。 - Maven : Packaging Jar on local filesystem, but not in WAR file. 读取HDFS上的txt文件并将其内容复制/写入到本地文件系统上新创建的文件时出错 - Error in reading a txt file on HDFS and copying/writing the content of it into a newly created file on LOCAL filesystem 如何设置动态路径 <local-path> weblogic.xml中的虚拟目录映射的说明 - how to set dynamic path for <local-path> of virtual directory mapping in weblogic.xml 爬行本地文件系统 - 如何测试 - Crawling local filesystem - how to test that 将远程文件下载到本地文件系统后,如何配置spring-integration-sftp来移动它? - How to configure spring-integration-sftp to move a remote file after it has been downloaded to local filesystem? 使用Primefaces上传文件系统上的文件 - Upload a file on filesystem with Primefaces
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM