SHOW:
|
|
- or go back to the newest paste.
1 | package tick; | |
2 | ||
3 | - | import java.io.FileInputStream; |
3 | + | import java.io.BufferedReader; |
4 | import java.io.FileNotFoundException; | |
5 | import java.io.FileReader; | |
6 | import java.io.IOException; | |
7 | import java.util.ArrayList; | |
8 | - | import java.util.Scanner; |
8 | + | |
9 | ||
10 | - | public class FileReader { |
10 | + | public class TickFileReader { |
11 | ||
12 | - | private final String FILE_LOCATION = System.getProperty("user.home")+"/Dropbox/tick/data/Info.txt"; |
12 | + | public static final String FILE_LOCATION = "./data/Info.txt"; |
13 | - | public static List<String> list; |
13 | + | public static List<String> list = new ArrayList<>(); |
14 | - | private final FileInputStream FILE_INPUT; |
14 | + | |
15 | - | private static Scanner scanner; |
15 | + | /** |
16 | * Reads tickfile data from <code>FILE_LOCATION</code>. | |
17 | - | public FileReader() throws IOException { |
17 | + | |
18 | - | FILE_INPUT = new FileInputStream(FILE_LOCATION); |
18 | + | |
19 | - | scanner = new Scanner(FILE_INPUT); |
19 | + | try(BufferedReader br = new BufferedReader(new FileReader(FILE_LOCATION))){ |
20 | - | list = new ArrayList<String>(); |
20 | + | String s; |
21 | while((s = br.readLine()) != null) { | |
22 | list.add(s); | |
23 | } | |
24 | - | * start reading data from txt file. once read close the input |
24 | + | |
25 | } | |
26 | ||
27 | - | while (scanner.hasNextLine()) |
27 | + | |
28 | - | synchronized (list) { |
28 | + | |
29 | - | list.add(scanner.nextLine()); |
29 | + | |
30 | public static void searchForWordInFile(final String WORD_SEARCHING_FOR) throws IOException { | |
31 | - | scanner.close(); |
31 | + | try(BufferedReader br = new BufferedReader(new FileReader(FILE_LOCATION))) { |
32 | String s; | |
33 | while((s = br.readLine()) != null) { | |
34 | if(WORD_SEARCHING_FOR.equals(s.trim())) { | |
35 | //found | |
36 | } else { | |
37 | - | public static void searchForWordInFile(final String WORD_SEARCHING_FOR) { |
37 | + | |
38 | - | while (scanner.hasNextLine()) { |
38 | + | |
39 | - | if (WORD_SEARCHING_FOR.equals(scanner.nextLine().trim())) { |
39 | + | |
40 | - | // found |
40 | + | |
41 | - | switch (WORD_SEARCHING_FOR) { |
41 | + | |
42 | - | // TODO |
42 | + | |
43 | - | // ADD SOME LOGIC FOR WHEN A WORD IS FOUND I.E WHAT TODO WITH |
43 | + |