通过gui调用的exec方法的错误处理

时间:2018-06-27 06:44:44

标签: java exec

我正在尝试使用java exec命令从SVN中签出。我正在通过线程处理输入流和错误流。以下是我正在处理它们的代码。我将所有这些代码都放在UI后面。基本上会在遇到错误时显示弹出窗口。这样做的最佳方法是什么?

public class SVNReadStream implements Runnable {
    String name;
    InputStream is;
    Thread thread;      
    public SVNReadStream(String name, InputStream is) {
        this.name = name;
        this.is = is;
    }       
    public void start () {
        thread = new Thread (this);
        thread.start ();
    }       
    public void run () {
        try {
            InputStreamReader isr = new InputStreamReader (is);
            BufferedReader br = new BufferedReader (isr); 

           // String s=null;
            if(this.name.contains("ErrorStream")){
                File file = new File(Constants.directory+this.name);

                PrintWriter writer = new PrintWriter(file);
                while (true) {
                    String s = br.readLine ();
                    if (s == null) break;
                    writer.write(s);

                }
                writer.flush();
                writer.close();
            }else{
            while (true) {
                String s = br.readLine ();
                if (s == null) break;

            }
            }
            is.close ();
            is.close (); 
            br.close();

        } catch (Exception ex) {
            System.out.println ("Problem reading stream " + name + "... :" + ex);

            ex.printStackTrace ();
        }
    }
}

0 个答案:

没有答案