prader6

读取根目录下的图片并输出到指定位置

public class Test2 {
    public static void main(String[] args) throws IOException {

        InputStream resourceAsStream = Test2.class.getResourceAsStream("/image/image_1.png");
        FileOutputStream fileOutputStream = new FileOutputStream("D://test.png");
        BufferedInputStream bufferedInputStream = new BufferedInputStream(resourceAsStream);
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
        byte[] bytes = new byte[1024];
        while (bufferedInputStream.read(bytes) != -1){
            bufferedOutputStream.write(bytes);
        }
        bufferedOutputStream.flush();
        bufferedOutputStream.close();
        bufferedInputStream.close();
    }
}

 

posted on 2019-04-12 15:28  prader6  阅读(401)  评论(0编辑  收藏  举报

导航