文件输入输出处理(五)-DataInputStream,DataOutputStream
作者:互联网
1、实例化
DataInputStream(InputStream in) | 参数是一个字节输入流 |
---|---|
DataOutputStream(OutputStream out) | 参数是一个字节输出流 |
演示
DataInputStream dis = new DataInputStream(new FileInputStream("D:/test/girl.jpg"));
DataOutputStream dos = new DataOutputStream(new FileOutputStream("D:/test/girl2.jpg"));
2、举例
复制图片
try(
DataInputStream dis = new DataInputStream(new FileInputStream("D:/test/girl.jpg"));
DataOutputStream dos = new DataOutputStream(new FileOutputStream("D:/test/girl2.jpg"));
){
//字符缓冲区
byte[] bytes = new byte[10];
//读取长度
int hasread = 0;
while((hasread = dis.read(bytes))>0){
dos.write(bytes,0,hasread);
}
//刷新缓冲区
dos.flush();
System.out.println("图片复制成功");
}catch (Exception e){
e.printStackTrace();
}
标签:输入输出,jpg,dos,DataInputStream,DataOutputStream,test,new 来源: https://www.cnblogs.com/xiaoqigui/p/16392974.html