流相关

来源:互联网 发布:数据库冷备份和热备份 编辑:程序博客网 时间:2024/05/16 09:04

1.BufferedReader提供通用的缓冲方式文本读取

try {            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("ming.txt")));            String data = null;            while((data = br.readLine())!=null)          //读取一个文本行,从字符输入流中读取文本            {                System.out.println(data);            }        } catch (FileNotFoundException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        }

2.InputStreamReader 字节流通向字符流的桥梁

try {            int ch;            InputStreamReader isr = new InputStreamReader(new FileInputStream("ming.txt"));            while((ch = isr.read())!=-1)            {                System.out.print((char)ch);            }        } catch (FileNotFoundException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        }


0 0
原创粉丝点击