码迷,mamicode.com
首页 > 编程语言 > 详细

java逐行读取和写入文本文件txt

时间:2015-12-15 22:30:59      阅读:622      评论:0      收藏:0      [点我收藏+]

标签:

逐行写入文本

public class TestFileWriter {
    public static void main(String[] args) {
        FileWriter fw = null;
        try {
            fw = new FileWriter("d://test.txt",true);
            String c = "abs"+"\r\n";
            fw.write(c);
            fw.close();
        } catch (IOException e1) {
            e1.printStackTrace();
            System.out.println("写入失败");
            System.exit(-1);
        }
    }
}

逐行读取文本

public static final void readF1(String filePath) throws IOException {      
        BufferedReader br = new BufferedReader(new InputStreamReader(
        new FileInputStream(filePath)));
        for (String line = br.readLine(); line != null; line = br.readLine()) {
                           System.out.println(line);               

        }
        br.close();
    }

java逐行读取和写入文本文件txt

标签:

原文地址:http://www.cnblogs.com/1130136248wlxk/p/5049677.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!