标签:
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException;
public class CopyFile{
public static void copyBytesFile(String sFileName,String dFileName)
throws IOException{
//创建文件输入流对象和文件输出流对象
FileInputStream fis = new FileInputStream(sFileName);
FileOutputStream fos = new FileOutputStream(dFileName);
//循环读取文件的内容,同时写出到外部文件
int read = fis.read();//从关联的源文件读一个字节,如果到达文件末的话,返回值为-1。
while(read != -1){
fos.write(read);//向其关联的目标文件写出一个字节
read = fis.read();
}
//清空缓存关闭流对象 fis.close(); fos.close(); }
public static void main(String[] args) { // TODO Auto-generated method stub Long t1,t2; t1 = System.currentTimeMillis();
try { CopyFile.copyBytesFile("a.mp3", "temp.mp3"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } t2 = System.currentTimeMillis(); System.out.println(" 用时 " + (t2 - t1)); } }
标签:
原文地址:http://www.cnblogs.com/zhaofanchao/p/5399684.html