Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class File extends Thread {
- ArrayList<String> filelist;
- File(ArrayList<String> filelist) {
- this.filelist = new ArrayList<String>();
- }
- public static ArrayList<String> readFile(String name) throws FileNotFoundException {
- Scanner scanner = null;
- scanner = new Scanner(new BufferedReader(new FileReader(name)));
- ArrayList<String> filelist = new ArrayList<String>();
- while (scanner.hasNextLine()) {
- filelist.add(scanner.nextLine());
- }
- scanner.close();
- return filelist;
- }
- public void observeFiles(String name) throws FileNotFoundException, InterruptedException {
- ArrayList<String> baseFile;
- ArrayList<String> observableFile;
- boolean b = true;
- while (b) {
- baseFile = File.readFile(name);
- Thread.sleep(5000);
- observableFile = File.readFile(name);
- if (!baseFile.equals(observableFile)) {
- System.out.println("There are a mistake");
- } else {
- System.out.println("OK");
- }
- baseFile.clear();
- baseFile.addAll(observableFile);
- }
- }
- public void run() {
- try {
- this.observeFiles(name);
- } catch (FileNotFoundException ex) {
- System.out.print("There are no files with such name!");
- return;
- } catch (InterruptedException ex) {
- System.out.print("fff");
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement