将IE缓存中的文件copy到其它目录下
2007-11-06 17:36
239 查看
/**
*
*/
package myweb.web;
/**
* @author sxc 石新春
*@Create date 2007-11-6
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
public class CopyFiles {
// 源路径
private static String SRC_DIREC = "C://Documents and Settings//zhangl//Local Settings//Temporary Internet Files";
//文件类型
private static String[] FILE_TYPE = {"mp3","bmp","gif","jpg","js","png","swf","asx","wma","wmv","css"};
private static String CURR_FILE_TYPE;
// 目的路径
private static String DEST_DIREC_ROOT = "E://";
private static String DEST_DIREC = "";
private static int num = 0;
// main方法
public static void main(String[] args) {
for(int i =0;i<FILE_TYPE.length;i++){
DEST_DIREC = DEST_DIREC_ROOT+FILE_TYPE[i];
CURR_FILE_TYPE = FILE_TYPE[i];
copyDelete(args);//copy
}
System.out.println("操作完成");
}
/**
* @param args
*/
private static void copyDelete(String[] args) {
// System.out.println("请输入要拷贝的文件路径及目的路径");
if (args.length == 0) {
args = new String[] { SRC_DIREC, DEST_DIREC };
}
File pathName = new File(args[0]);
String[] fileNames = pathName.list();
// 遍历文件夹,找出所要文件
int i = 0;
for (; i < fileNames.length; i++) {
File f = new File(pathName.getPath(), fileNames[i]);
if (f.isDirectory()) {
//
copyDelete(new String[] { f.getPath(), DEST_DIREC });
} else if (f.getName().endsWith("."+CURR_FILE_TYPE)){
num++;
makeDirIfNotExist(args[1]);
System.out.print(num+"、正在复制文件:" + f.getName() + " 到目录" + args[1] + ".../t");
copyfile(f.getAbsolutePath(), args[1]+"//" + f.getName());
f.delete();
System.out.println("复制成功。源文件删除成功。");
}
}
}
/**
* 复制文件到新路径下
*
* @param src
* @param dest
*/
private static void copyfile(String src, String dest) {
try {
FileChannel srcChannel = new FileInputStream(src).getChannel();
// Create channel on the destination
FileChannel dstChannel = new FileOutputStream(dest).getChannel();
// Copy file contents from source to destination
dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
// Close the channels
srcChannel.close();
dstChannel.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void makeDirIfNotExist(String adir){
File dir = new File(adir);
if(!dir.exists()){
System.out.println("文件夹 "+adir+" 不存在,创建之");
dir.mkdir();
}
}
}
*
*/
package myweb.web;
/**
* @author sxc 石新春
*@Create date 2007-11-6
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
public class CopyFiles {
// 源路径
private static String SRC_DIREC = "C://Documents and Settings//zhangl//Local Settings//Temporary Internet Files";
//文件类型
private static String[] FILE_TYPE = {"mp3","bmp","gif","jpg","js","png","swf","asx","wma","wmv","css"};
private static String CURR_FILE_TYPE;
// 目的路径
private static String DEST_DIREC_ROOT = "E://";
private static String DEST_DIREC = "";
private static int num = 0;
// main方法
public static void main(String[] args) {
for(int i =0;i<FILE_TYPE.length;i++){
DEST_DIREC = DEST_DIREC_ROOT+FILE_TYPE[i];
CURR_FILE_TYPE = FILE_TYPE[i];
copyDelete(args);//copy
}
System.out.println("操作完成");
}
/**
* @param args
*/
private static void copyDelete(String[] args) {
// System.out.println("请输入要拷贝的文件路径及目的路径");
if (args.length == 0) {
args = new String[] { SRC_DIREC, DEST_DIREC };
}
File pathName = new File(args[0]);
String[] fileNames = pathName.list();
// 遍历文件夹,找出所要文件
int i = 0;
for (; i < fileNames.length; i++) {
File f = new File(pathName.getPath(), fileNames[i]);
if (f.isDirectory()) {
//
copyDelete(new String[] { f.getPath(), DEST_DIREC });
} else if (f.getName().endsWith("."+CURR_FILE_TYPE)){
num++;
makeDirIfNotExist(args[1]);
System.out.print(num+"、正在复制文件:" + f.getName() + " 到目录" + args[1] + ".../t");
copyfile(f.getAbsolutePath(), args[1]+"//" + f.getName());
f.delete();
System.out.println("复制成功。源文件删除成功。");
}
}
}
/**
* 复制文件到新路径下
*
* @param src
* @param dest
*/
private static void copyfile(String src, String dest) {
try {
FileChannel srcChannel = new FileInputStream(src).getChannel();
// Create channel on the destination
FileChannel dstChannel = new FileOutputStream(dest).getChannel();
// Copy file contents from source to destination
dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
// Close the channels
srcChannel.close();
dstChannel.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void makeDirIfNotExist(String adir){
File dir = new File(adir);
if(!dir.exists()){
System.out.println("文件夹 "+adir+" 不存在,创建之");
dir.mkdir();
}
}
}
相关文章推荐
- Linux命令:cp (copy)复制文件或目录
- 将指定目录的所有文件及文件夹copy到指定目录下,只copy 7天内创建的或是7天内修改过的
- VS工程中如何在其它目录下的文件中包含stdafx.h的问题
- 读取文件图标及目录Copy[2006-10-16]
- window下面使用copy命令把其它文件隐藏到图片中且图片能正常使用
- shell脚本----cp (copy)复制文件或目录
- java读取excel文件并复制(copy)文件到指定目录示例
- linux中cp (copy)复制文件或目录的用法
- maven copy file文件到指定目录
- copy命令及库文件至/mnt/sysroot/目录shell脚本
- Linux命令:cp (copy)复制文件或目录
- [eclipse使用]采用直接copy plugins和features文件夹到eclipse目录方式安装pdt文件失败的问题
- shtml中用include引入文件方法(包括其它目录下文件)
- Ubuntu_Linux命令:cp (copy)复制文件或目录
- VBS自动将IE缓存目录复制过来的文件改名
- COPY目录下的所有子目录和文件到其他目录
- ubuntu下复制目录和文件的指令以及和windows下的copy方式
- copy带空格时的目录或文件
- 修改 mysql-binlog 二进制日志文件至其它目录
- shell脚本----cp (copy)复制文件或目录