Created
July 14, 2020 06:06
-
-
Save guozi/706af58d55e9c9b07b6bd5ad00501a04 to your computer and use it in GitHub Desktop.
Parse .txt to .csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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