IO編程——文件複製操作

將某個文件複製到指定目錄。

package com.file;

import java.io.*;

public class test4 {

	
	public static void main(String[] args) {
		FileInputStream fis = null;
		FileOutputStream fos =null;
		
		try {
			fis = new FileInputStream("d:\\qlg.jpg");
			fos = new FileOutputStream("e:\\qlg_復件.jpg");
			byte []buf = new byte[1024]; 
			int n = 0;
			while ((n=fis.read(buf)) != -1){
				fos.write(buf);	//輸出到指定文件
			}
		} catch (Exception e) {
			// TODO 自動生成的 catch 塊
			e.printStackTrace();
		}finally{	//關閉流
			try {
				fis.close();	
				fos.close();
			} catch (IOException e) {
				// TODO 自動生成的 catch 塊
				e.printStackTrace();
			}
		}

	}

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章