1 . 演示文件的copy
package com.yx.demo1;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.junit.Test;
/*
* 本类用于演示复制文件
*/
public class TestCopyFile {
@Test
public void testOne()throws Exception{
File oldFile = new File("src\\test.txt");//原文件
File newFile = new File("src\\test_bak.txt");//副本文件
if(!newFile.exists()){
newFile.createNewFile();
}
// FileInputStream fis = new FileInputStream(oldFile);//跟原文件建立输入流,从原文件中读取数据。
// FileOutputStream fos = new FileOutputStream(newFile);//跟副本文件建立输出流,把从原文件中读取的数据写到副本文件中。
// byte[] data = new byte[1024];
//
// int length;
// //while((length = fis.read(data)) != -1){
// //fos.write(data, 0, length)
// //}
// while(true){
// length = fis.read(data);
//