0

I want to execute notepad(C:\a.txt) after typing another char.

This code open a.txt with notepad but when i was write "Java" , i want to show my console Java. after when i was write " then Java" i want to show my console Java then Java".

Process process = Runtime.getRuntime().exec("notepad.exe C:\\a.txt");
InputStreamReader read = new InputStreamReader(process.getInputStream());
while(read.read() != -1){
System.out.println(read.read());
}
Franz Kafka
  • 10,623
  • 20
  • 93
  • 149
kibar
  • 822
  • 3
  • 17
  • 37

2 Answers2

1

You won't be able to read what's going on in Notepad this way.

getInputStream()/getOutputStream allow you to write to and read from the standard input and output of a process, but these streams typically have nothing to do with the user interface of a desktop application. Notepad isn't going to echo things that happen in it's user interface to these streams.

You can monitor the file system for changes to a.txt but this assumes that you're saving the file after each change in Notepad.

pb2q
  • 58,613
  • 19
  • 146
  • 147
0

If you want to detect changes while file is opened you can use https://blogs.oracle.com/thejavatutorials/entry/watching_a_directory_for_changes#register and then re-read the file with the code you provided

Ljudevit
  • 368
  • 3
  • 12