-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViDuDocText.java
More file actions
53 lines (48 loc) · 1.47 KB
/
Copy pathViDuDocText.java
File metadata and controls
53 lines (48 loc) · 1.47 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.scene.shape.Path;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author thien
*/
public class ViDuDocText {
public static void main(String[] args) {
/*cách 1
File f = new File("C:\\Java\\ReadFileInJava\\file.txt");
try {
BufferedReader br = Files.newBufferedReader(f.toPath(),StandardCharsets.UTF_8);
String line = null;
while(true){
line = br.readLine();// đọc từng dòng
if(line==null){
break;
}else{
System.out.println(line);
}
}
} catch (IOException ex) {
Logger.getLogger(ViDuDocText.class.getName()).log(Level.SEVERE, null, ex);
}*/
// cách 2
File f2 = new File("C:\\Java\\ReadFileInJava\\file.txt");
try {
List<String> allText = Files.readAllLines(f2.toPath(),StandardCharsets.UTF_8);
for (String line : allText) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}