java IO流 將一張圖片拷貝到另外一個地方


import java.io.File;
import java.io.FileInputStream;

import java.io.FileOutputStream;
import java.io.IOException;

public class DemoCopy {

/**
 * @param args
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
	// TODO Auto-generated method stub
	copy();
	
}
public static void copy() throws IOException{
	
	//1.讀取數據輸入字節流
	//找到圖片路徑
	File file  = new File("D:\\img\\01.jpg");
	
	FileInputStream inputStream = new FileInputStream(file);
	//2.寫入數據輸出字節流
	File file1  = new File("D:\\01.jpg");
	FileOutputStream outputStream = new FileOutputStream(file1);
	
	byte [] b = new byte[1024];
	
	
	
	while (inputStream.read(b)!=-1) {
		
		outputStream.write(b);
		
	}
	//關閉流  關閉流原則:先開后關,后開先關。
	
	outputStream.close();
	inputStream.close();
	  
	
	
}

}


免責聲明!

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



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