栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java读写txt 文件-代码实例

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java读写txt 文件-代码实例


源数据:5306行*15列

public class WindLoad01 {

    public static void main(String[] args) throws Exception {

        File file1 = new File("C:/Users/zzyuan/Desktop/test.txt");

        //存取数据
        double[][] map = new double[5306][15];

        int n = map.length;
        int m = map[0].length;

        BufferedReader br = new BufferedReader(new FileReader(file1));

        String[] line = null;
        String s = "";
        String str = "";
        int index = 0;

        while ((s = br.readLine()) != null){
            line = s.split("\s+");
            for(int j = 0 ; j < 15 ; j++){
                map[index][j] = Double.parseDouble(line[j]) - Double.parseDouble(line[j+15]);
                map[index][j] *= 31;
                str = String.format("%.2f",map[index][j]);
                map[index][j] = Double.parseDouble(str);
            }
            index++;
        }

        File file2 = new File("C:/Users/zzyuan/Desktop/out.txt");

        BufferedWriter wr = new BufferedWriter(new FileWriter(file2));
        for (int i = 0; i < map.length; i++) {
            for (int j = 0; j < map[0].length; j++) {
                wr.write(map[i][j] + "t");
            }
            wr.write("rn");
        }

        //关闭数据流
        br.close();
        wr.close();
    }
}

结果:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/868428.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号