java io 文件的拷贝2

修正了自己的错误


大郅解释就是,文件夹的话下面如放abc文件夹下,abc\\


package homework;


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;


import IOStream.filecopy;


/*
 * 1.实现 文件的复制和文件夹的复制  如果指定的位置有相同的文件 提供覆盖功能


 2.统计指定的文件中的 数字  字母  标点  分别一共有多少个  使用StreamTokenizer 


 */
public class c4_1 {
public static void main(String args[]) throws Exception {
File file = new File("H:/学习文件/大三上复习/期末/java/JAVA程序设计实验");
File[] files = file.listFiles();


// File file1 = new File("i:\\abc\\");

String file2 = new String("i:\\abc\\");
(new File(file2)).mkdirs();


for (File f : files) {
if (!f.isDirectory()) {
String name = f.getName();
BufferedInputStream bis = new BufferedInputStream(
new FileInputStream(f));
// 无法放入一个文件里
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(file2 + name));
int hasread = 0;
byte[] a = new byte[1024 * 4];
while ((hasread = bis.read(a)) != -1) {
bos.write(a);
bos.flush();


}


bos.close();
} else {
String name = f.getName();
(new File(file2 + name)).mkdirs();

}
}
}




}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值