字节流复制单个文件
// 复制单个文件代码
public static void main(String[] args) throws IOException {
//获取当前时间s
long s=System.currentTimeMillis();
//创建字节输入流对象,读取的数据源
FileInputStream fis=new FileInputStream("c:\\WiFi_Log.txt");
//创建字节输出流对象,读取的数据源
FileOutputStream fos=new FileOutputStream("d:\\WiFi_Log.txt");
//使用数组缓冲读取多个字节,写入1024个字节
byte[] bytes=new byte[1024];
//记录有效读取
int len=0;
//read读取的字节传给bytes数组中
while((len=fis.read(bytes))!=-1){
//输出流write方法将bytes数组内容写入到fos文件中,从0开始,写入len位字节
fos.write(bytes,0,len);
}
//释放资源,先关闭写的,再关闭读的
fos.close();
fis.close();
//获取当前时间e
long e=System.currentTimeMillis();
System.out.println("文件耗时:"+(e-s)+"毫秒");
}
今天的你也辛苦了!