转换流

@Test
    public void test4() throws IOException {
        InputStreamReader isr = null;
        try {
            FileInputStream fis = new FileInputStream("D:\\java.txt");
            isr = new InputStreamReader(fis,"UTF-8");
            char[] cbuf = new char[5];
            int len = 0;
            while ((len = isr.read(cbuf))!=-1){
                System.out.print(new String(cbuf,0,len));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(isr!=null)
                isr.close();
        }
    }

  

posted @ 2022-09-01 21:13  iTao0128  阅读(15)  评论(0)    收藏  举报