1. 程式人生 > >java -- 讀取和輸出圖片到本地

java -- 讀取和輸出圖片到本地

    public static byte[] getLocalPicture() throws Exception {
        byte[] data = null;
        FileImageInputStream input = new FileImageInputStream(new File(
                "d://HaierVR.jpg"));
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        int
numBytesRead = 0; while ((numBytesRead = input.read(buf)) != -1) { output.write(buf, 0, numBytesRead); } data = output.toByteArray(); output.close(); input.close(); return data; } public static void writeLocalPicture(byte[] data) throws
Exception { FileImageOutputStream imageOutput = new FileImageOutputStream(new File( "e://123.jpg")); imageOutput.write(data, 0, data.length); imageOutput.close(); }