字节缓冲流

构造方法

方法名 说明
BufferedOutputStream(OutputStream out) 创建字节缓冲输出流对象【write】
BufferedInputStream(InputStream in) 创建字节缓冲输入流对象【read】

字节缓冲流复制

package io_bytetheflow.IOliu;
import java.io.*;
public class bufferStreamCopyDemo {
public static void main(String[] args) throws IOException {
//复制视频
/* BufferedInputStream bis = new BufferedInputStream(new FileInputStream("E:\\java\\vd.avi"));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("E:\\java1\\vd1.avi"));
int by;
while ((by=bis.read())!=-1) {
bos.write(by);
}
System.out.println("复制成功!");
bos.close();
bis.close();
*/
BufferedInputStream bis1 = new BufferedInputStream(new FileInputStream("E:\\java1\\vd1.avi"));
BufferedOutputStream bos1 = new BufferedOutputStream(new FileOutputStream("E:\\java\\vd11.avi"));
byte[] bys = new byte[1024];
int len;
while ((len=bis1.read(bys))!=-1) {
bos1.write(bys,0,len);
}
System.out.println("复制成功!");
bos1.close();
bis1.close();
}
}

字符流

为什么会出现字符流

编码表

字符串中的编码解码问题

public class StringDemo {
public static void main(String[] args) throws UnsupportedEncodingException {
//定义一个字符串
String s = "中国";
//byte[] bys = s.getBytes(); //[-28, -72, -83, -27, -101, -67]
//byte[] bys = s.getBytes("UTF-8"); //[-28, -72, -83, -27, -101, -67]
byte[] bys = s.getBytes("GBK"); //[-42, -48, -71, -6]
System.out.println(Arrays.toString(bys));
//String ss = new String(bys);
//String ss = new String(bys,"UTF-8");
String ss = new String(bys,"GBK");
System.out.println(ss);
}
}

发表回复