-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadfromTxt.java
More file actions
58 lines (50 loc) · 1.68 KB
/
Copy pathReadfromTxt.java
File metadata and controls
58 lines (50 loc) · 1.68 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
54
55
56
57
58
package src.thinkinginjava.IO18;
import java.io.*;
import java.util.LinkedList;
/**
* Created by Ryan on 2017/3/20.
*/
public class ReadfromTxt {
public static void main(String[] args) {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("src/thinkinginjava/res/test.txt"));
LinkedList<String> linkedList = new LinkedList<>();
String string;
while ((string = br.readLine()) != null) {
linkedList.push(string);
}
System.out.println(linkedList.size());
for (String s: linkedList) {
if (s.matches("hi.*"))
System.out.println(s);
}
int a = linkedList.size();
for (int i = 0; i < a; i++) {
System.out.println(linkedList.pop().toUpperCase());
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
String a = "this is a test";
try {
br = new BufferedReader(new StringReader(a));
DataInputStream dataInputStream = new DataInputStream(new BufferedInputStream(
new FileInputStream("src/thinkinginjava/res/test.txt")));
while (dataInputStream.available() != 0) {
System.out.println((char) dataInputStream.readByte());
}
while ((a = br.readLine()) != null) {
System.out.println(a);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}