How can I Monitor External files in Java

后端 未结 2 704
小鲜肉
小鲜肉 2020-12-22 04:59

I have a .exe file, It takes .txt file as a Input and it returns .txt files as outputs.

I have 2 folders names are Inpu

相关标签:
2条回答
  • 2020-12-22 05:31

    For running an external process (a .exe program in this case), forget about Runtime.exec(). Instead use ProcessBuilder; the documentation states that it's the preferred way to start up a sub-process these days.

    0 讨论(0)
  • 2020-12-22 05:31

    Follow this quick tutorial over running .exe from java. It should be sufficient (4pages)

    http://www.javaworld.com/jw-12-2000/jw-1229-traps.html?page=1

    example

    import java.util.*;
    import java.io.*;
    
    public class GoodWindowsExec
    {
        public static void main(String args[])
        {
    
    
            try
            {            
    
    
                Runtime rt = Runtime.getRuntime();
    
                Process proc = rt.exec("cmd.exe /C ping"); // executing ping through commandshell of windows
    
                proc.getErrorStream() // errorstream
    
                proc.getInputStream()  // outputstream
    
    
                int exitVal = proc.waitFor(); // wait till process ends    
            } catch (Throwable t)
              {
                t.printStackTrace();
              }
        }
    }
    
    0 讨论(0)
提交回复
热议问题