今日总结

ava实现spark统计100万人口的平均年龄以及每个年龄的出现次数,数据格式为“序号 年龄”

//生成年龄数据,格式“序号  年龄”
    private static void makeAgeData() throws IOException {
        File newFile = new File("src/main/files/peopleAges.txt");
        if (newFile.exists()){
            System.out.println("文件已存在!");
            return;
        }
        newFile.createNewFile();
        FileWriter fw = new FileWriter(newFile,true);
        Random rand = new Random();
        for (int i=1;i<=1000000;i++){
            fw.append(i+"  "+(rand.nextInt(100)+1)+"\n");
            fw.flush();
        }
        fw.close();
    }

 

posted @ 2024-01-22 22:01  北·岛  阅读(9)  评论(0)    收藏  举报