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

读取数据文件

时间:2015-05-10 12:36:02      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:

/* 以 Stream后缀结尾 的都为 字节流, 而以Reader或Writer后缀结尾的叫做字符流 */
class TestFileReaderWriter {

    public void copyfile() {
        int c = 0;
        try {
            
            BufferedReader br = new BufferedReader(new FileReader("E:/Postgraduate/Cluster of Qiao‘s thesis/social network/dataset/irise-BufferedReaderWriter.txt"));//缓冲流,效率更高
            BufferedWriter bw = new BufferedWriter(new FileWriter("E:/Postgraduate/Cluster of Qiao‘s thesis/social network/dataset/irise-BufferedReaderWriter.txt"));
            String s = null;
            
            for (int i = 0; i < 100; i++) {
                s=String.valueOf(Math.random());
                bw.write(s);
                bw.newLine();
            }
            bw.flush();
            while((s = br.readLine())!=null) 
                System.out.println(s);
            bw.close();
            br.close();
        } catch (FileNotFoundException e) {
            System.out.println("找不到指定文件");
        } catch (IOException e) {
            System.out.println("文件读取错误");
        }
        System.out.println("文件已经复制");
    }
}

 

读取数据文件

标签:

原文地址:http://www.cnblogs.com/pacoson/p/4491953.html

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