public class file3 {
//字节输出流
/**
* 拷贝图片*/
public static void main(String[] args) {
try {
//源文件
FileInputStream fis = new FileInputStream("c:/logo.png");
FileOutputStream fos = new FileOutputStream("d:/logo1.png");
//一次拷贝1K缓冲
byte [] buf = new byte[1024];
//循环拷贝
int read = 0;
while ((read=fis.read(buf)) != -1);{
//写缓冲 从0开始到读到的位置
fos.write(buf,0,read);
}
fos.flush();
fos.close();
fis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
error:
Exception in thread "main" java.lang.IndexOutOfBoundsException
at java.base/java.io.FileOutputStream.writeBytes(Native Method)
at java.base/java.io.FileOutputStream.write(FileOutputStream.java:347)
at file3.main(file3.java:21)
Process finished with exit code 1