InputStreamReader类的构造函数
- InputStreamReader(InputStream in)
//创建InputStreamReader对象,构造方法中传递输入流,使用默认字符集 - InputStreamReader(InputStream in, String charsetName)
//创建InputStreamReader对象,构造方法中传递输入流,使用指定字符集 - InputStreamReader(InputStream in, Charset cs)
//创建InputStreamReader对象,构造方法中传递输入流,使用给定字符集对象 - InputStreamReader(InputStream in, CharsetDecoder dec)
//创建InputStreamReader对象,构造方法中传递输入流,使用给定字符集解码器
01
创建InputStreamReader对象,构造方法中传递输入流
public class File01 {
public static void main(String[] args) throws IOException {
FileInputStream fileInputStream = new FileInputStream("D:\\");
InputStreamReader in = new InputStreamReader(fileInputStream);
}
}
02
创建InputStreamReader对象,构造方法中传递输入流和指定的编码表名称
public class File02 {
public static void main(String[] args) throws IOException {
FileInputStream fileInputStream = new FileInputStream("D:\\");
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "GBK");
}
}
03
public class File03 {
public static void main(String[] args) throws IOException {
Charset charset = Charset.forName("ISO-2022-CN");
FileInputStream fileInputStream = new FileInputStream("D:\\");
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, charset);
}
}
04
public class File04 {
public static void main(String[] args) throws IOException {
Charset charset = Charset.forName("ISO-2022-CN");
CharsetDecoder decoder = charset.newDecoder();
FileInputStream fileInputStream = new FileInputStream("D:\\");
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, decoder);
}
}