-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamEx2.java
More file actions
29 lines (24 loc) · 824 Bytes
/
StreamEx2.java
File metadata and controls
29 lines (24 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.java8.streams;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;
// to get the data from the files
public class StreamEx2 {
public static void main(String[] args) throws FileNotFoundException, IOException {
try(
FileReader fr = new FileReader("sample.txt");
BufferedReader br = new BufferedReader(fr);
){
br.lines().forEach(System.out :: println);
}
System.out.println("---------------------------------");
// getting the values with the help of streams only
try(Stream<String> st = Files.lines(Paths.get("sample.txt"))){
st.forEach(System.out :: println);
}
}
}