LoginSignup
0
0

More than 1 year has passed since last update.

FileInputStream class

Posted at

FileInputStreamを使用して画像の読み込み
FileOutputSttreamを使用して画像の書き込み

public class Outer {
    public static void main(String[] args) {
        try {
            FileInputStream fis = new FileInputStream("C:\\dirtest\\cook.jpg");
            BufferedInputStream ibs = new BufferedInputStream(fis);
            FileOutputStream fos = new FileOutputStream("C:\\dirtest\\cookcpy.jpg");
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            try(ibs;bos) {
                while(true) {
                    byte[] bt = ibs.readNBytes(1024);   //1024byte づつread
                    if(bt.length == 0) break;
                    bos.write(bt);
                    bos.flush();
                }
            }
        } catch (IOException ex ){
            ex.printStackTrace();
        }
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0