Skip to content

Instantly share code, notes, and snippets.

@rahulkumar-aws
Created December 17, 2017 13:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rahulkumar-aws/b6175e8909c456dd90d3b62546dcad7e to your computer and use it in GitHub Desktop.
Save rahulkumar-aws/b6175e8909c456dd90d3b62546dcad7e to your computer and use it in GitHub Desktop.
Java 8 Read csv file
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