- package com.mine;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- public class 拷贝E盘张孝祥高新视频 {
- public static void main(String[] args) throws Exception {
- String src = "E:\\Study\\张泽华\\张孝祥2010年贺岁视频:Java高新技术\\55_张孝祥Java高新技术_编写可生成代理和插入通告的通用方法(1)";
- String tar = "E:\\Study\\高新";
- copySrcToTar(src,tar);
- }
- private static void copySrcToTar(String src, String tar) throws Exception {
- File srcDir=new File(src);
- File tarDir=new File(tar);
- if (!tarDir.exists()||!tarDir.isDirectory()) {
- tarDir.mkdir();
- }else{
- File[] files = srcDir.listFiles();
- for (File file : files) {
- if (file.isDirectory()) {
- copySrcToTar(file.getAbsolutePath(), tar);
- }else{
- copy(file,tarDir);
- }
- }
- }
- }
- private static void copy(File file, File tarDir) throws Exception {
- BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(file)));
- PrintWriter pw=new PrintWriter(tarDir+"\\"+file.getName());
- String line;
- while ((line=br.readLine())!=null) {
- pw.write(line);
- pw.flush();
- }
- br.close();
- pw.close();
- br=null;
- pw=null;
- }
- }
复制代码
|
|