简体   繁体   English

java.io.File诉org.apache.commons.vfs2.FileObject

[英]java.io.File v. org.apache.commons.vfs2.FileObject

I'm trying to monitor a folder for a batch file that will be dropped there to make updates to a web app. 我正在尝试监视一个批处理文件的文件夹,该文件将被拖放到该文件夹​​中以更新Web应用程序。 The app already uses the Apache vfs2 library and I've been advised by my lead to use this as well. 该应用程序已经使用了Apache vfs2库,我的主管也建议我也使用它。

My question is this: what is the conceptual difference between File in java.io and FileObject in org.apache.commons.vfs2? 我的问题是:java.io中的File和org.apache.commons.vfs2中的FileObject之间在概念上有什么区别?

I've read the docs at FileObject and File and what I'm really looking for is a conceptual distinction of these two classes. 我已经阅读了FileObjectFile上的文档,而我真正想要的是这两个类的概念区别。 For example: is FileObject some kind of wrapper around File? 例如:FileObject是File周围的某种包装吗? I don't see much in common in their inheritance trees so it doesn't seem to me like FileObject is using File anywhere. 我在它们的继承树中看不到太多共同之处,因此在我看来FileFile在任何地方都使用File。

The VFS2 FileObject is an interface with no ties to a specific storage mechanism (this is the point of the VFS2 filesystem) VFS2 FileObject是与特定存储机制无关的接口(这是VFS2文件系统的关键)

A FileObject can represent a local filesystem file, a file on an SFTP, FTP, HTTP or WebDav server, or a file inside a compressed archive, or any other thing you can think of that might hold a collection of bytes that make up a file. FileObject可以表示本地文件系统文件,SFTP,FTP,HTTP或WebDav服务器上的文件或压缩存档内的文件,或者您可以想到的任何其他可能包含构成文件的字节的集合。

java.io.File is a reference to a local file, and that's the end of it. java.io.File是对本地文件的引用, java.io.File

The benefit of the FileObject abstraction is that you can code to a single interface, and not care about where the bytes that make up that file actually come from (ie local filesystem, streamed via SFTP over SSH, via HTTP etc.) FileObject抽象的好处是您可以编码到单个接口,而不用担心组成该文件的字节实际来自何处(即本地文件系统,通过SSH通过SFTP,HTTP等流式传输)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM