Help us understand the problem. What is going on with this article?

Read input File, Edit, and Output to TSV File

More than 3 years have passed since last update.

package csvUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

/**
* Read input File, Edit, and Output to TSV File。
*
* @author hal
*/
public class CsvTest {

public static void main(String[] args) {

    String inputFile = "D:\\pleiades\\workspace\\csvUtils\\src\\csvUtils\\input.txt";
    String outputFile = "D:\\pleiades\\workspace\\csvUtils\\src\\csvUtils\\output.tsv";

    try {//ファイル 処理が隠蔽され内部で完結するので、戸締りの心配もいらない。
        List<String> lines = Files.readAllLines(Paths.get(inputFile));

        List<String> outputList = new ArrayList<String>();

        final String header = "サイトCD\t予約日\tCap会員ID";

        outputList.add(header);

        lines.stream()
        .filter(t -> t.length() >= 95)
        .map(t -> t.replaceAll("\\s", ""))
        .forEach(t -> {
            System.out.println(t);

            String outputText = t.substring(30, 33) + "\t";
            outputText = outputText + t.substring(63, 71) + "\t";
            outputText = outputText + t.substring(84, 95);

            outputList.add(outputText);
        });

        Files.write(Paths.get(outputFile), outputList, StandardCharsets.UTF_8);

    } catch (IOException e) {
        e.printStackTrace();
    }
}

}

halhal
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away