java拷贝文件
java拷贝文件
FileInputStream
FileOutputStream
package com.vfsd.core; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class CopyFileAndRename { public static void copyFile(String oldFileName,String newFileName) throws IOException { File oldFile = new File(oldFileName); File newFile = new File(newFileName); FileInputStream fileInputStreamObj = new FileInputStream(oldFile); FileOutputStream fileOutputStreamObj = new FileOutputStream(newFile); byte[] bytes = new byte[1024]; int len1 = -1; while((len1=fileInputStreamObj.read(bytes))!=-1) { fileOutputStreamObj.write(bytes, 0, len1); fileOutputStreamObj.flush(); } fileOutputStreamObj.flush(); fileOutputStreamObj.close(); fileInputStreamObj.close(); } }
###########################
QQ 3087438119