JAVA 隔N行取一行寫入新文字,遍歷TXT文字

abcjob發表於2021-09-09
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+"rn");
                }
                kk++;
            }
            num++;
            readerText.close();
            if (num> N) {
                break;
            }
        }
        writerText.close();
    }

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/4798/viewspace-2807792/,如需轉載,請註明出處,否則將追究法律責任。

相關文章