Fetch InputStream of a running process from a file path

Viewed 24

I'm currently trying to make a program that can take in a file path, such as

File file = new File("D:\\Servers\\TestServer\\server.jar");

and if it is running, retrieve the running process's InputStream to be read. I have been able to accomplish this if I start the process myself (in the program), but what if the given process was already running by the time the program opened?

I've tried things such as the following:

InputStream inputStream = new FileInputStream(file);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bis = new BufferedReader(inputStreamReader);

String line;
while ((line = bis.readLine()) != null) {
    System.out.println(line);
}

But, this reads the file itself, not it's running process (I think, at least). Anything helps, thanks!

I'm a bit new to programming so please let me know if there's any more information you may need and I can gladly provide it. Thanks :-)

0 Answers
Related