字节流:
InputStream:FileInputStream
OutputStream: FileOutputStream
任意一张图片粘贴到对应的项目下
代码:
public void fileInputStreamCopy() {
FileInputStream fileInputStream = null;
FileOutputStream fileOutputStream = null;
try {
fileInputStream = new FileInputStream("bd_logo.png");
fileOutputStream = new FileOutputStream("bd_logo_back.png");
byte[] buffer = new byte[1024];//字节数组
int length = 0;
while ((length = fileInputStream.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, length);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}