字符流
作者:互联网
package com.czie.iot1913.lps.IO.InPutStream;
import java.util.Arrays;
/**
* FileName: FileInPutStream03
* Author: lps
* Date: 2022/3/26 11:56
* Sign:刘品水 Q:1944900433
* <p>
* 一个汉字存储如果是gbk编码是两个字节
* 如果utf—8是3个字节
*/
public class FileInPutStream03 {
public static void main(String[] args) throws Exception {
// FileInputStream fis = new FileInputStream("F:\\JavaCode\\fos.txt");
// int by;
// while ((by=fis.read())!=-1){
// System.out.print((char) by);
// }
//hello
//world
//ååæ°´
// FileInputStream fis = new FileInputStream("F:\\JavaCode\\fos.txt");
// byte[] bys = new byte[1024];
// int len;
// while ((len=fis.read(bys))!=-1){
// System.out.println(new String(bys,0,len));
// }
//hello
//world
//刘品水
//String s="abc";//[97, 98, 99]
String s = "中国";//[-28, -72, -83, -27, -101, -67]
// byte[] bys = s.getBytes();
// byte[] bys = s.getBytes(StandardCharsets.UTF_8);//[-28, -72, -83, -27, -101, -67]
byte[] bys = s.getBytes("GBK");//[-42, -48, -71, -6]
System.out.println(Arrays.toString(bys));
//字符流=字节流+编码表
//UTF-8是三位 GBK是两位
//fis.close();
}
}
标签:字符,String,fis,bys,new,FileInputStream,byte 来源: https://www.cnblogs.com/lps1944900433/p/16058373.html