Advertisement
Mary_Loskutova

Test

Mar 20th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. public class File {
  2.  
  3.     ArrayList<String> filelist;
  4.  
  5.     File(ArrayList<String> filelist) {
  6.         this.filelist = new ArrayList<String>();
  7.     }
  8.  
  9.     public static File readFile(String name) throws FileNotFoundException {
  10.         Scanner scanner = null;
  11.         scanner = new Scanner(new BufferedReader(new FileReader(name)));
  12.         ArrayList<String> filelist = new ArrayList<String>();
  13.         while (scanner.hasNextLine()) {
  14.             filelist.add(scanner.nextLine());
  15.         }
  16.         File file = new File(filelist);
  17.         return file;
  18.     }
  19. }
  20.  
  21. public class Spy extends Thread {
  22.     ArrayList<File> fileCollection;
  23.  
  24.     public Spy() {
  25.         this.fileCollection = new ArrayList<File>();
  26.     }
  27.  
  28.     public void obsFile(File filelist) throws InterruptedException {
  29.         boolean b = true;
  30.         while (b) {
  31.             this.fileCollection.add(filelist);
  32.             Thread.sleep(1500);
  33.             int a = fileCollection.size() - 1;
  34.             System.out.println(fileCollection.get(0).equals((fileCollection.get(a))));
  35.         }
  36.     }
  37. }
  38.  
  39. public class Test {
  40.     public static void main(String[] args) throws InterruptedException {
  41.  
  42.         System.out.print("Enter the first file name" + "\n");
  43.         Scanner sc = new Scanner(System.in);
  44.         String Name = sc.nextLine();
  45.         try {
  46.             File file1 = File.readFile(Name);
  47.             Spy spy = new Spy();
  48.             spy.obsFile(file1);
  49.  
  50.         } catch (FileNotFoundException ex) {
  51.             System.out.print("There are no files with such name!");
  52.             sc.close();
  53.             return;
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement