0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Read input File, Edit, and Output to TSV File

Posted at

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();
     }
    

    }
    }

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?