Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class File extends Thread {
- ArrayList<String> example;
- String name;
- File(String name) {
- this.name = name;
- this.example = new ArrayList<String>();
- this.setDaemon(true);
- }
- 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 static void finishTracking () {
- }
- public void observeFiles() 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("There are no changes in the file " + name);
- }
- baseFile.clear();
- baseFile.addAll(observableFile);
- }
- }
- public void run() {
- try {
- this.observeFiles();
- } catch (FileNotFoundException ex) {
- System.out.print("There are no files with such name!");
- return;
- } catch (InterruptedException ex) {
- System.out.print("Tracking has been stopped");
- return;
- }
- }
- }
- import java.util.Scanner;
- import test.Menu;
- import test.MenuEntry;
- import java.util.InputMismatchException;
- public class Test2 {
- public static void main(String[] args) {
- Menu menu = new Menu();
- Scanner sc = new Scanner(System.in);
- menu.addEntry(new MenuEntry("Start tracking file") {
- @Override
- public void run() {
- System.out.print("Enter the file name" + "\n");
- String entry = sc.nextLine();
- File file = new File(entry);
- file.setName(entry);
- file.start();
- }
- });
- menu.addEntry(new MenuEntry("Stop tracking file") {
- @Override
- public void run() {
- System.out.println("Enter the number: 1.Stop" + "2.Cancel and return" + "\n");
- boolean b = true;
- while (b) {
- try {
- int input = sc.nextInt();
- switch (input) {
- case 1:
- return;
- case 2:
- return;
- default:
- System.out.print("Wrong input!" + "\n");
- break;
- }
- } catch (InputMismatchException ex) {
- System.out.print("Wrong input!");
- }
- }
- }
- });
- menu.addEntry(new MenuEntry("Send e-mail") {
- @Override public void run() {
- System.out.println( "Enter adress");
- String adress = sc.nextLine();
- MailSender mailsender = new MailSender ();
- mailsender.setProperties();
- mailsender.sendMessage(adress);
- }
- });
- menu.run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement