Advertisement
Mary_Loskutova

File

Mar 26th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.40 KB | None | 0 0
  1. import java.io.FileNotFoundException;
  2. import java.io.FileReader;
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6.  
  7. public class File extends Thread {
  8.  
  9.     ArrayList<String> filelist;
  10.    
  11.  
  12.     File(ArrayList<String> filelist) {
  13.         this.filelist = new ArrayList<String>();
  14.     }
  15.  
  16.     public static ArrayList<String> readFile(String name) throws FileNotFoundException {
  17.         Scanner scanner = null;
  18.         scanner = new Scanner(new BufferedReader(new FileReader(name)));
  19.         ArrayList<String> filelist = new ArrayList<String>();
  20.         while (scanner.hasNextLine()) {
  21.             filelist.add(scanner.nextLine());
  22.         }
  23.         scanner.close();
  24.         return filelist;
  25.        
  26.     }
  27.  
  28.     public void observeFiles(String name) throws FileNotFoundException, InterruptedException {
  29.         ArrayList<String> baseFile;
  30.         ArrayList<String> observableFile;
  31.         boolean b = true;
  32.         while (b) {
  33.             baseFile = File.readFile(name);
  34.             Thread.sleep(5000);
  35.             observableFile = File.readFile(name);
  36.             if (!baseFile.equals(observableFile)) {
  37.                 System.out.println("There are a mistake");
  38.             } else {
  39.                 System.out.println("OK");
  40.             }
  41.             baseFile.clear();
  42.             baseFile.addAll(observableFile);
  43.         }
  44.     }
  45.  
  46.     public void run() {
  47.         try {
  48.            
  49.             this.observeFiles(name);
  50.  
  51.         } catch (FileNotFoundException ex) {
  52.             System.out.print("There are no files with such name!");
  53.             return;
  54.         } catch (InterruptedException ex) {
  55.             System.out.print("fff");
  56.             return;
  57.         }
  58.     }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement