-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDemo.java
More file actions
52 lines (45 loc) · 1.4 KB
/
Demo.java
File metadata and controls
52 lines (45 loc) · 1.4 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
import javax.sound.midi.Soundbank;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class demo {
// to handle exceptions include throws
public static void main(String[] args)
{
List listOfStrings = new ArrayList<String>();
BufferedReader bf = null;
try {
bf = new BufferedReader(
new FileReader("D:\\DSA\\wordFinder\\src\\res\\sample.txt"));
} catch (FileNotFoundException e) {
System.out.println("");
}
if(bf != null) {
String line = null;
try {
line = bf.readLine();
while (line != null) {
listOfStrings.add(line);
line = bf.readLine();
}
} catch (IOException e) {
System.out.println("");
}
}
if(bf !=null) {
try {
bf.close();
} catch (IOException e) {
System.out.println("");
}
}
//String[] array = listOfStrings.toArray(new String[0]);
System.out.println(listOfStrings);
// for (String str : listOfStrings) {
// System.out.println(str);
// }
}
}