java FileInputStream 与FileOutputStream 实现读出写入流, 复制图片

void CopyImage(){
try {
String filePath ="/users/yifei/desktop/assets/timg.gif";
File f = new File(filePath);
f.setWritable(true);
f.setReadable(true);
FileInputStream fis = new FileInputStream(f);
FileOutputStream fos = new FileOutputStream("/users/yifei/desktop/assets/timeg1.gif");
int n =0;
byte[] b = new byte[2048];
int i = 0;
while((n=fis.read())!=-1) {//读出并写入
fos.write(n);
}
System.out.println(“123”);

		fis.close();
		fos.close();
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}catch (IOException e) {
		e.printStackTrace();
	}

}

猜你喜欢

转载自blog.csdn.net/weixin_41069726/article/details/86508305