下面的程序我是将指定目录下所有内容复制到另一个目录文件中,不包括复制文件夹。但不知道为什么复制不了。谁帮忙找一下问题出在哪里?随便跟大家分享一下。
/**
* @param args
* @throws Exception
*/
static FileInputStream in = null;
static FileOutputStream out = null;
static BufferedInputStream buffin = null;
static BufferedOutputStream buffout = null;
public static void main(String[] args) throws Exception {
File file = new File("E:\\myuser\\wen1");
List<File> list = new ArrayList<File>();
fileList(file, list);
CopyFileJava(list);
}
public static void CopyFileJava(List<File> list) throws Exception {
byte[] buff = new byte[1024];
int len = 0;
try {
for (File file : list) {
String name = file.getName();
out = new FileOutputStream("E:\\myuser\\my\\");
in = new FileInputStream(file.toString());
buffin = new BufferedInputStream(in);
buffout = new BufferedOutputStream(out);
while ((len = buffin.read(buff)) != -1) {
buffout.write(buff, 0, len);
}
}
} catch (Exception e) {
throw e;
} finally {
try {
if (buffin != null) {
buffin.close();
}
if (buffout != null) {
buffout.close();
}
} catch (Exception e) {
throw e;
}
}
}
public static void fileList(File file, List<File> list) {
File filenPath[] = file.listFiles();
for (File path : filenPath) {
if (path.isDirectory()) {
fileList(path, list);
} else {
if(path.getName().endsWith(".java")){
list.add(path);
}
}
}
} |
|