Skip to content

Instantly share code, notes, and snippets.

@guozi
Created July 14, 2020 06:06
Show Gist options
  • Save guozi/706af58d55e9c9b07b6bd5ad00501a04 to your computer and use it in GitHub Desktop.
Save guozi/706af58d55e9c9b07b6bd5ad00501a04 to your computer and use it in GitHub Desktop.
Parse .txt to .csv
public class ParseToCsc {
public static void main(String[] args) throws Exception {
final Path path = Paths.get("path", "to", "folder");
final Path txt = path.resolve("myFile.txt");
final Path csv = path.resolve("myFile.csv");
try (
final Stream<String> lines = Files.lines(txt);
final PrintWriter pw = new PrintWriter(Files.newBufferedWriter(csv, StandardOpenOption.CREATE_NEW))) {
lines.map((line) -> line.split("\\|")).
map((line) -> Stream.of(line).collect(Collectors.joining(","))).
forEach(pw::println);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment