手记

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

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();
    }
1人推荐
随时随地看视频
慕课网APP