Created
December 17, 2017 13:27
-
-
Save rahulkumar-aws/b6175e8909c456dd90d3b62546dcad7e to your computer and use it in GitHub Desktop.
Java 8 Read csv file
This file contains 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
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
import java.util.stream.Stream; | |
public class ReadCSV { | |
public static void main(String[] args) { | |
String fileName = "domains.csv"; | |
try (Stream<String> lines = Files.lines(Paths.get(fileName))) { | |
List<List<String>> values = lines.map(line -> Arrays.asList(line.split(","))).collect(Collectors.toList()); | |
values.forEach(value -> System.out.println(value)); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment