java核心api_Java核心API之字符流使用介绍
InputStreamReader的構造方法
InputStreamReader有如下幾個構造方法,但是最常用的是InputStreamReader(InputStream in, String charsetName),改構造方法第一個參數是字節流,第二個參數是字符集字符串
代碼片段如下:
/*
* InputStreamReader構造方法
* InputStreamReader(InputStream in)
*
* InputStreamReader(InputStream in, String charsetName)
*
* InputStreamReader(InputStream in, Charset cs)
*
* InputStreamReader(InputStream in, CharsetDecoder dec)
*/
@Test
public void testISRContructor() throws Exception{
FileInputStream fis = new FileInputStream("rw.txt");
//構造方法InputStreamReader(InputStream in)參數傳入一個字節流
InputStreamReader isr = new InputStreamReader(fis);
//構造方法InputStreamReader(InputStream in, String charsetName)
//第一個參數是字節流,第二個參數是字符集字符串
InputStreamReader isr2 = new InputStreamReader(fis,"UTF-8");
//構造方法InputStreamReader(InputStream in, Charset cs)
//第一個參數是字節流,第二個參數是字符集類
Charset cs = Charset.forName("UTF-8");
InputStreamReader isr3 = new InputStreamReader(fis,cs);
//構造方法InputStreamReader(InputStream in, CharsetDecoder dec)
//第一個參數是字節流,第二個參數是編碼器
CharsetDecoder dc = cs.newDecoder();
InputStreamReader isr4 = new InputStreamReader(fis,dc);
}
總結
以上是生活随笔為你收集整理的java核心api_Java核心API之字符流使用介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python编码注释和平台注释_pyth
- 下一篇: 个人养老保险要交多少年