package com.d04_file.itheima06;
import com.sun.javafx.runtime.async.AbstractRemoteResource;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
public class FileInputStreamDemo {
public static void main(String[] args) throws IOException {
FileInputStream fil = new FileInputStream("src\\com\\d04_file\\itheima06\\a.txt");
byte[] by = new byte[1024];
int len;
// while ((len = fil.read())!=-1){
// System.out.println((char) len);
// }
while ((len = fil.read(by))!=-1){
System.out.println(new String(by,0,len));
}
/*
byte[] getBytes() 使用平台的默认字符集将该 String编码为一系列字节
byte[] getBytes(String charsetName) 使用指定的字符集将该 String编码为一系列字节
*/
String s = "中国";
byte[] bb = s.getBytes("GBK"); //一个中文占两个gbk字节,3个UTF-8字节
System.out.println(Arrays.toString(bb));
fil.close();
}
}