使用文件字節流實現文件復制


package com.study02;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class TestFileCopy {
public static void main(String[] args) {

FileInputStream fis;
try {



//數據源文件
fis = new FileInputStream("aaa.txt");


//數據目的文件
FileOutputStream fos = new FileOutputStream("bbb.txt");

byte[] buf = new byte[1024];
int len = 0;

while((len = fis.read(buf))!=-1) {
fos.write(buf,0,len);
}

// int b = 0;
// while((b = fis.read())!=0) {
// fos.write(b);
// }
if(fos!=null) {
fos.close();
}
if (fis!=null) {
fis.close();
}


} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}





}

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM