apache VFS 简单使用

import org.apache.commons.vfs.FileChangeEvent; import org.apache.commons.vfs.FileContent; import org.apache.commons.vfs.FileDepthSelector; import org.apache.commons.vfs.FileFilter; import org.apache.commons.vfs.FileFilterSelector; import org.apache.commons.vfs.FileListener; import org.apache.commons.vfs.FileMonitor; import org.apache.commons.vfs.FileName; import org.apache.commons.vfs.FileObject; import org.apache.commons.vfs.FileSelectInfo; import org.apache.commons.vfs.FileSelector; import org.apache.commons.vfs.FileSystemException; import org.apache.commons.vfs.FileSystemManager; import org.apache.commons.vfs.FileType; import org.apache.commons.vfs.VFS; import org.apache.commons.vfs.impl.DefaultFileSystemManager; import org.apache.commons.vfs.impl.StandardFileSystemManager; import org.apache.commons.vfs.operations.FileOperation; import org.apache.commons.vfs.operations.FileOperations; import org.apache.commons.vfs.provider.FileProvider; import org.apache.commons.vfs.provider.FileReplicator; import org.apache.commons.vfs.provider.TemporaryFileStore; import org.apache.commons.vfs.provider.VfsComponent; import org.apache.commons.vfs.provider.VfsComponentContext;

public class Main {

        public static void main(String agrs[]) throws FileSystemException {
                    /**
                     * **文件基本操作***
                     */
                    //文件:目录和普通文件 访问文件内容和结构

// FileObject fo = null; // //文件名 // FileName fn = fo.getName(); // //文件类型 // FileType ft = fo.getType(); // //文件的读取(文件的内容) // FileContent fc = fo.getContent(); // 读文件 // fc.getInputStream(); // 写文件 // fc.getOutputStream(); // //文件的操作(创建,删除,重命名,拷贝) // fo.createFile(); // fo.copyFrom(fo, null); // fo.delete(); // 文件操作扩展(版本控制) // FileOperations foo = fo.getFileOperations(); // /** // * 文件监听和监控* // / // FileListener fl; // FileMonitor fm; // /* // * 文件过滤器和选择器* // / // FileFilter ff; // FileSelectInfo fsi; // FileSelector fs; // demo: // FileFilter ffdemo = new FileFilter() { // // public boolean accept(FileSelectInfo fsi) { // FileObject fo = fsi.getFile(); // return fo.getName().getBaseName().startsWith("."); // } // }; // FileSelector fs = new FileSelector() { // //此处当目录下有文件名203\49\jdfkd.pdf时,报错,把\当作路径处理 // // // public boolean includeFile(FileSelectInfo fsi) throws Exception { // FileObject fo = fsi.getFile(); // return fo.getName().getBaseName().startsWith("a"); // } // // public boolean traverseDescendents(FileSelectInfo fsi) throws Exception { // return true; // } // }; // FileSystemManager sfm = VFS.getManager(); // FileObject fo = sfm.resolveFile("/home/zcwangjb/temp"); // FileObject[] fos = null; // //fos=fo.findFiles(new FileFilterSelector(ffdemo)); // //fos = fo.getChildren(); // fos = fo.findFiles(fs); // for (FileObject f : fos) { // System.out.println(f.getName().getBaseName()); // } // /* // * ** 事件*** // / // FileChangeEvent fce; //只有改变时间 // /* // * 重要对象* // / // VFS vfs; // FileSystemManager fsm=null; //文件系统管理器接口 // 通过文件系统使用名字来定位文件 // 绝对URI ,必须以协议Schema开始 // //不同的协议可能需要额外的jar包支持,比如:http协议需要apache-commons httpclient支持 // 绝对的本地路径 // 相对的本地路径 // fsm.resolveFile(""); // 1. file:/home/zcreader 2. /home/zcreader 3. ../home // VfsComponent vfsComponent = null; //管理VFS所有组建的生命周期,维护一个组建上下文 // VfsComponentContext componentContext = null; //允许组建访问他们需要的服务,如下 // FileReplicator fileReplicator = null; //创建本地的文件复制品 // TemporaryFileStore temporaryFileStore = null; //负责管理本地临时文件仓库 // FileProvider fileProvider = null; //每一个特定的文件提供器负责处理相应的特定类型URI模式,例如HTTP,FTP /* * 文件管理器解析文件* */ FileSystemManager fileSystemManager = VFS.getManager(); DefaultFileSystemManager defaultFileSystemManager = null; StandardFileSystemManager standardFileSystemManager = null; //解析文件有StandardFileSystemManager的resolveFile()方法完成 standardFileSystemManager.resolveFile("");

                    /**
                     * ** 缓存、 认证、 ant task ***
                     */
        }

}

转载于:https://my.oschina.net/kingwjb/blog/261865

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值