I'm using java.awt.Robot I was wondering if it is possible for java to scan a constantly updating log.txt file and output those key events to an external program.
example: if text.txt has the string "up" within it, java.awt.Robot will output this keyevent externally and interpret it as keyboard arrow up and continue on each time text.txt has been updated.
is it possible for java.awt.Robot to only register certain words like up down left right and ignore any other word.
I am very new to java so apologies if some things are horribly wrong.
this is the scanner script, the scanner script works fine if the log file simply has up, down, left, right etc in it but if its large chucks of paragraphs the script returns null.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ScannerReadFile {
public static void main(String[] args) {
// Location of file to read
File file = new File("text.txt");
Scanner scanner = null;
try {
scanner = new Scanner(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (scanner != null) {
String line;
while (scanner.hasNextLine()) {
line = scanner.nextLine();
if ("up".equals(line)) {
System.out.println(line);
}
if ("down".equals(line)) {
System.out.println(line);
}
if ("left".equals(line)) {
System.out.println(line);
}
if ("right".equals(line)) {
System.out.println(line);
}
}
}
}
}
Thanks