Navigation of this series of articles
Apache VFS (1): Basic Introduction
Apache VFS (2): file monitoring and monitoring
Apache VFS (3): file filter and Selector
Apache VFS (4): Events
Apache VFS (5): use it!
Apache VFS (6): several important conceptual Interfaces
Apache VFS (7): File Manager File Parsing Method
Apache
VFS
It provides a virtual file system that allows you to easily deal with local file systems, FTP file systems, and HTTP files through programs.
In Apache
VFS
CoreFileObject Interface
.
It represents a file, and Java
File has more extended functions and information. There are many file objects implementing the FileObject interface: for example, the AbstractFileObjet abstract class provides some
FileObject implementation. Most FileObject implementation classes inherit the AbstractFileObject class:
- LocalFile: (it's strange why it's not LocalFileObject)
- Ftpfileobject
- Httpfileobject
- Sftpfileobject
- Zipfileobject
- Tarfileobject
- Ramfileobject
- Urlfileobject
- Delegatefileobject
- Compressedfileobject
FileObject represents a file that can be used to access the file content and structure. Files are organized in hierarchies. Each hierarchies forms a file system. A file system is like a file system in a local operating system, such as a Windows File System, an Http server, or a Zip file package.
There are two types of files:Directory
AndCommon File
. Common files have data or content, while directories do not include content. They can only contain other files. Common files cannot contain other files.
File Name
FileObject has a FileName object. The object name is processed as an independent object. The file name is unchangeable. There are many methods for object names:
- Getbasename
- Getdepth
- Getextension
- Getfriendlyuri
- Getparent
- Getpath
- Getroot
- And so on.
File Content reading
Note: Unlike Java File, FileObject hasFilecontent object
To access the file content, use the FileObject. getFileContent () method. This method returns a FileContent object. FileContent indicates the content of a file.
To put it simply, use: FileContent.Getinputstream ()
Use: FileContent.Getoutputstream ()
There isFinal abstractfileobject
.
Important FileContent methods include:
- Close all resources used to close the file content, including all open file streams.Be careful !!
- GET/set attribute/attributes: it cannot be used currently. Unless you rewrite it yourself, you actually call the doget/setattribute method of abstractfileobject.
- Getcontentinfo returnsContentInfo object
The ContentInfo OBJECT records the content type and encoding information.
- Getinputstream Read File Content
- Getoutputstream Write File Content
- IsOpen check to see if the file has opened the file stream
- GetFile returns the FileObject object.
- Get/setLastModifiedTime
File Operations
You can use FileObject to create, delete, rename, and copy basic file operations.
- CopyFrom (FileObject src, FileSelector selector) copies from the source file in other places to this file, including the source file sub-files, there is a file selector parameter and the source file parameter
- Delete () delete this file
- Delete (FileSelector selector) deletes all sub-files of the file that match the file selector.
- CreateFile () if this file does not exist, create it
- CreateFolder () If this directory does not exist, create it
VFS
To support advanced operations, such as working with version control tools, FileOperation objects are provided, but VFS
There is no implementation at all. If you want to play, you can do it yourself.
Criticize VFS here
: VFS
Of
Some aspects of development are unreasonable. For example, FileObject supports setting attributes for files. Later, it was found that its AbstractFileObject
The getAttributes () method returns only one empty Map, and the setAttribute () method throws an unsupported exception. This function is very simple. If you
If necessary, change it. Therefore, use VFS
Pay attention to these traps.On your own risk!
Source: http://alartin.javaeye.com/blog/92053