Java Exception 捕获和展示(二)

2014-11-24 03:16:53 · 作者: · 浏览: 1
试 */ public void test(){ try { String content = readFile(); System.out.println(content); String regEx = "Caused by:(.*)"; Pattern pat = Pattern.compile(regEx); Matcher mat = pat.matcher(content); boolean rs = mat.find(); System.out.println("found " + rs); System.out.println(mat.group(1)); // for(int i=1;i<=mat.groupCount();i++){ // System.out.println("found:" + mat.group(i)); // } } catch (Exception e) { e.printStackTrace(); } } public void test2(){ try { FileInputStream fis = new FileInputStream("d:\\test.txt"); fis.read(); } catch (Exception e) { e.printStackTrace(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); e.printStackTrace(new PrintStream(baos)); String exception = baos.toString(); System.out.println("exception:" + exception); } } public static void main(String[] args) { RegexpTest rt = new RegexpTest(); //rt.test(); rt.test2(); }