继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

JAVA 隔N行取一行写入新文本,遍历TXT文本

尘T陌
关注TA
已关注
手记 17
粉丝 10
获赞 81
public static void Train_dataSet() throws IOException {
        String ReadPath = "dataset/TrainInput/train_set";//
        String WritPath = "dataset/TrainInput/train_set_001";//
        FileWriter writerText = new FileWriter(WritPath+"_.txt", true);
        int num = 0;
        int N = 100;
        while(1==1){
            int kk=0;
            BufferedReader readerText= new BufferedReader(new FileReader(ReadPath+"_.txt"));
            for(String line = readerText.readLine(); line != null; line = readerText.readLine()){   
                if ((kk+num)% N ==0) {
                    writerText.write(line+"\r\n");
                }
                kk++;
            }
            num++;
            readerText.close();
            if (num> N) {
                break;
            }
        }
        writerText.close();
    }
打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP