A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© woshiku 中级黑马   /  2015-9-14 14:23  /  295 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

public class ReadLineDemo {
        private void readDemo(){
                try {
                        //创建缓存流对象
                        BufferedReader fis = new BufferedReader(new FileReader("c:\\puke\\test.txt"));
                        //用于获取文本
                        String line = null;
                        try {
                                //读行行,如果返回null
                                while((line=fis.readLine())!=null){
                                        System.out.println(line);
                                }
                        } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                        try {
                                //读完关闭流
                                fis.close();
                        } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }

        /**
         * @param args
         */
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                new ReadLineDemo().readDemo();
        }

}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马