package copyfile;
import java.io.*;
public class copy {
public static void main(String[] args) throws IOException {
copyFile("d:/new/a.txt","d:/new/b.txt",true);//oldpath,newpath,是否不覆盖前文
}
public static void copyFile(String oldpth,String newpath,boolean add) throws IOException{
FileInputStream in = null;
FileOutputStream fs = null;
try {
//实例化文件,并判断文件是否存在
File oldfile=new File(oldpth);
if(oldfile.exists()){
//初始化文件输入与输出流
in=new FileInputStream(oldpth);
fs=new FileOutputStream(newpath,add);
//定义存放读取数据的数组
byte[] buffer=new byte[10];
int length;
while(true){
int len=in.read(buffer);//当文件读完,返回-1,否则返回读取文件长度
/*注:输出读取的当前文件内容方法
* String s=new