JDK6.0学习笔记(二十一)通用文件系统
来源:互联网 发布:mvp播放器mac下载 编辑:程序博客网 时间:2024/06/13 23:38
- import java.io.FileOutputStream;
- import java.io.File;
- import jcifs.smb.SmbFile;
- import jcifs.smb.SmbFileInputStream;
- public class TestCIFS {
- public static void main(String args[]) throws Exception {
- if (args == null || args.length < 5) {
- System.out
- .println("TestCIFS <host> <username> <password> <remote_path> <local_path>");
- System.exit(1);
- }
- String host = args[0];
- String username = args[1];
- String password = args[2];
- String path = args[3];
- String output_path = args[4];
- String full_path = "smb://" + username + ":" + password + "@" + host
- + path + (path.endsWith("/") ? "" : "/");
- System.out.println("SMB路径是:" + full_path);
- System.out.println("本地路径是:" + args[4]);
- SmbFile dir = new SmbFile(full_path);
- SmbFile files[] = dir.listFiles(new MySmbFileFilter());
- for (int i = 0; i < files.length; i++) {
- SmbFileInputStream in = new SmbFileInputStream(files[i]);
- int c = -1;
- String localFileName = files[i].getName();
- FileOutputStream fos = new FileOutputStream(new File(output_path
- + (path.endsWith("/") ? "" : "/") + localFileName));
- while ((c = in.read()) > -1)
- fos.write(c);
- in.close();
- fos.close();
- }
- }
- }
- import jcifs.smb.SmbFileFilter;
- import jcifs.smb.SmbFilenameFilter;
- import jcifs.smb.SmbException;
- import jcifs.smb.SmbFile;
- public class MySmbFileFilter implements SmbFilenameFilter {
- public MySmbFileFilter() {
- }
- public boolean accept(SmbFile dir, String name) {
- if (name != null && name.startsWith("hello"))
- return true;
- else
- return false;
- }
- }