-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadBook.java
More file actions
46 lines (40 loc) · 1.18 KB
/
ReadBook.java
File metadata and controls
46 lines (40 loc) · 1.18 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
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class ReadBook {
// Book b;
public static void main(String[] args) {
}
public String Search(String keyword) {
String invalid = "Nothinhg found. Please try again.";
ArrayList<Book> bl = new ArrayList<>();
try {
File file = new File("bookInventory.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String st;
while ((st = br.readLine()) != null) {
String[] info = st.split(",");
Book b = new Book(info[0], info[1], info[2], Boolean.parseBoolean(info[3]));
if (keyword.equalsIgnoreCase(b.getTitle())
||keyword.equalsIgnoreCase(b.getGenre())
||keyword.equalsIgnoreCase(b.getAuthor())) {
bl.add(b);
}
else {
return invalid ;
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bl.toString().replace('[',' ').replace(']',' ').replace(", ","").trim();
}
}