美文网首页
JAVA在本地生成多个文件

JAVA在本地生成多个文件

作者: 开心的小哈 | 来源:发表于2020-09-07 14:29 被阅读0次
    public void set3() throws IOException {
            for(int h=0;h<120;h++) {
                
            File file = new File("G://test/ces"+h+".txt");
            if(!file.exists()) {
                file.createNewFile();
            }else {
                file.delete();
                file.createNewFile();
            }
            FileWriter fw = new FileWriter(file,true);
            BufferedWriter bw = new BufferedWriter(fw);
             List<String> actions = Arrays.asList("riding", "running", "swimming");
             List<String> userNames = Arrays.asList("lily", "tom", "bob");
             List<String> times = Arrays.asList("2018-2-2", "2018-3-3");
             for(int i= 0; i<1000; i++) {
                 for(String username: userNames) {
                     for(String action: actions) {
                         for(String time: times) {
                             String request = username+" is "+action+" on "+time+"\r\n";
                             bw.write(request);
                         }
                     }
                 }
             }
             bw.flush();
             bw.close();
             fw.close();
            }
        }
    

    最终效果


    image.png

    相关文章

      网友评论

          本文标题:JAVA在本地生成多个文件

          本文链接:https://www.haomeiwen.com/subject/xyzkektx.html