標籤:put ring stream exist file otf package ack highlight
思路:首先把原有的圖片以流的方式讀取出來,再以流的方式儲存到目標檔案:
package imgStream;import java.io.*;public class ImgStream { public static void main(String srga[]) { File source = new File("user.jpg"); File desk = new File("G:\\learn\\javademoS\\imgs"); if (!desk.exists()) { desk.mkdir(); } try { FileInputStream inputStream = new FileInputStream(source); FileOutputStream outputStream = new FileOutputStream(new File("G:\\learn\\javademoS\\imgs\\fang.jpg")); int ch = inputStream.read(); while (ch != -1) {//當流結束時返回-1 outputStream.write(ch); ch = inputStream.read(); } inputStream.close(); outputStream.close(); System.out.println("寫入流成功"); } catch (FileNotFoundException e) { System.out.println("檔案不存在:" + e.getMessage()); } catch (IOException e) { System.out.println("檔案讀取錯誤:" + e.getMessage()); } }}
通過java的i/o機制進行圖片流的儲存