1. 程式人生 > >IO流大檔案操作----從一個檔案複製到另一個檔案

IO流大檔案操作----從一個檔案複製到另一個檔案

import java.io.*;
public class IOBase {
public static void main(String args[])
{
FileInputStream in=null;
FileOutputStream out=null;
byte[] b=new byte[10];


try {//輸入流的來源
in=new FileInputStream("E:/BaiduYunDownload/Java4Android/Java4Android/33_Java當中的IO(二)/from.txt");
//輸出流的去向
out=new FileOutputStream("E:/BaiduYunDownload/Java4Android/Java4Android/33_Java當中的IO(二)/tdddddd.txt");

while(true)
{//進行輸入操作
int num=in.read(b, 0, b.length);
if(num==-1)
{break;}
//進行輸出操作
out.write(b,0,b.length);
}



} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
try {//釋放關閉,相當於是水管子,當運水完成之後,進行拔管子操作
in.close();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


}
}