码迷,mamicode.com
首页 > 其他好文 > 详细

读写文件

时间:2016-08-01 19:04:03      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/*
 * 读取txt格式文本,并复制保存
 */
public class ReadFile {
    public static void main(String args[]) throws IOException{    
        File file = new File("/Users/xiaobai/testData/test1.txt");
        BufferedReader read = new BufferedReader(new FileReader(file));
        
        File file1 = new File("/Users/xiaobai/testData/test2.txt");
        BufferedWriter writer = new BufferedWriter(new FileWriter(file1));
        
        String text = null;
        while((text = read.readLine()) != null){
            System.out.println(text);
            writer.write(text);
            writer.newLine();
            writer.flush();
        }
        read.close();
        writer.close();
    }
}

 

读写文件

标签:

原文地址:http://www.cnblogs.com/worms/p/5726607.html

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