IO——转换流之BufferedReader

    xiaoxiao2026-08-27  16

    package com.io.ioDemo; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; /** * 字节转字符输出 * @author Administrator * */ public class InputStreamReaderDemo { public static void main(String[] args) { BufferedReader br = null; try { //1.注意转换流的实例化方式 //2.转换流的一个主要作用,调整编码格式,以防乱码 br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("c:\\isr.txt")),"utf-8")); String line=null; StringBuffer sb = new StringBuffer(); while((line = br.readLine()) != null){ sb.append(line+"\n"); } System.out.println(sb.toString()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } }
    转载请注明原文地址: https://ju.6miu.com/read-1311619.html
    最新回复(0)