Java iText操作PDF文档

来源:互联网 发布:阿里云招聘官网 编辑:程序博客网 时间:2024/06/01 09:16

 iLife's 博客http://blog.csdn.net/fei1502816 

1.Action

  1. //在线打印PDF  
  2. String path = servlet.getServletContext().getRealPath("");  //得到项目根目录  
  3. CreatePdf checkPdf = new CreatePdf();  
  4. String filepath = checkPdf.printImportAndPtExpert(path,"expertBase",importList,putongtList);  
  5. request.setAttribute("filepath", path+File.separator+"community"+File.separator+"pdfile"+File.separator+filepath);  
  6. return mapping.findForward("downLoad");  

 

2.公用类CreatPDF

  1. import java.io.File;  
  2. import java.io.FileOutputStream;  
  3. import java.util.List;  
  4.   
  5. import com.lowagie.text.Cell;  
  6. import com.lowagie.text.Document;  
  7. import com.lowagie.text.DocumentException;  
  8. import com.lowagie.text.Element;  
  9. import com.lowagie.text.Font;  
  10. import com.lowagie.text.FontFactory;  
  11. import com.lowagie.text.HeaderFooter;  
  12. import com.lowagie.text.Image;  
  13. import com.lowagie.text.PageSize;  
  14. import com.lowagie.text.Paragraph;  
  15. import com.lowagie.text.Phrase;  
  16. import com.lowagie.text.Rectangle;  
  17. import com.lowagie.text.Table;  
  18. import com.lowagie.text.Watermark;  
  19. import com.lowagie.text.pdf.BaseFont;  
  20. import com.lowagie.text.pdf.PdfPageEventHelper;  
  21. import com.lowagie.text.pdf.PdfWriter;  
  22.   
  23. public class CopyOfCreatePdf extends PdfPageEventHelper {  
  24.   
  25.     /** 
  26.      * 打印专家评审基地(重点基地和普通基地) 
  27.      *  
  28.      * @param path 
  29.      *            获得项目根目录 String path = 
  30.      *            servlet.getServletContext().getRealPath(""); 
  31.      * @param filename 
  32.      *            文件名 
  33.      * @param importList 
  34.      *            重点基地集合 
  35.      * @param putongList 
  36.      *            普通基地集合 
  37.      * @return 
  38.      * @throws Exception 
  39.      */  
  40.     @SuppressWarnings("unchecked")  
  41.     public String printImportAndPtExpert(String path, String filename,  
  42.             List importList, List putongList) throws Exception {  
  43.         // 创建报表大小,不能够指定页边距。  
  44.         // Document document = new Document(PageSize.A4, 85, 71, 72, 72);  
  45.         Document document = new Document(PageSize.A4, 30307272);  
  46.         try {  
  47.             BaseFont bfFS = BaseFont.createFont(path + File.separator  
  48.                     + "WEB-INF" + File.separator + "classes" + File.separator  
  49.                     + "fonts" + File.separator + "SIMFANG.TTF",  
  50.                     BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);  
  51.             // 华文细黑  
  52.             BaseFont bfHWXH = BaseFont.createFont(path + File.separator  
  53.                     + "WEB-INF" + File.separator + "classes" + File.separator  
  54.                     + "fonts" + File.separator + "STXIHEI.TTF",  
  55.                     BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);  
  56.             // 黑体  
  57.             BaseFont bfHT = BaseFont.createFont(path + File.separator  
  58.                     + "WEB-INF" + File.separator + "classes" + File.separator  
  59.                     + "fonts" + File.separator + "SIMHEI.TTF",  
  60.                     BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);  
  61.   
  62.             Font htFontB = new Font(bfHT, 14, Font.BOLD);  
  63.   
  64.             PdfWriter writer = PdfWriter.getInstance(document,  
  65.                     new FileOutputStream(path + File.separator + "community"  
  66.                             + File.separator + "pdfile" + File.separator  
  67.                             + filename + ".pdf"));  
  68.   
  69.             // 插入水印  
  70.             if (new File(path + File.separator + "image006.gif") != null) {  
  71.                 Watermark watermark = new Watermark(Image.getInstance(path  
  72.                         + File.separator + "image006.gif"), 0f, 0f);  
  73.                 document.add(watermark);  
  74.             } else {  
  75.                 System.out.println("添加水印失败");  
  76.             }  
  77.             com.lowagie.text.Font ST3 = FontFactory.getFont("STSong-Light",  
  78.                     "UniGB-UCS2-H");  
  79.             ST3.setSize(10f);  
  80.             HeaderFooter footer = new HeaderFooter(new Phrase("第", ST3),  
  81.                     new Phrase("页", ST3));  
  82.             footer.setBorder(Rectangle.NO_BORDER);  
  83.             footer.setAlignment(Element.ALIGN_CENTER);  
  84.             document.setFooter(footer);  
  85.             // 加密  
  86.             writer.setEncryption(PdfWriter.STRENGTH128BITS, null,  
  87.                     "hujichen0928", PdfWriter.AllowPrinting  
  88.                             | PdfWriter.AllowCopy);  
  89.             // 添加元信息  
  90.   
  91.             document.addAuthor("北京科学技术委员会");  
  92.             document.addSubject("评审基地项目列表");  
  93.             document.open();  
  94.   
  95.             com.lowagie.text.Font ST = FontFactory.getFont("STSong-Light",  
  96.                     "UniGB-UCS2-H");  
  97.             com.lowagie.text.Font ST22 = FontFactory.getFont("STSong-Light",  
  98.                     "UniGB-UCS2-H");  
  99.   
  100.             BaseFont baseFont2 = ST22.getBaseFont();  
  101.             Font ST2 = new Font(baseFont2, 14, Font.BOLD);  
  102.             com.lowagie.text.Font cnFont = new Font(bfHWXH);  
  103.             ST.setSize(10);  
  104.             ST2.setSize(12);  
  105.   
  106.             Table proinfoTab = new Table(8);  
  107.             proinfoTab.setWidth(100.0f);  
  108.             float[] twidth = { 6f, 8f, 14f, 14f, 14f, 6f, 6f, 28f };  
  109.             proinfoTab.setWidths(twidth);  
  110.             proinfoTab.setCellspacing(4);  
  111.             // 设置表框属性  
  112.             Cell proinfoCell = new Cell(new Paragraph("2011年北京市第五批基地申报专家评审表",  
  113.                     ST2));  
  114.             proinfoCell.setUseAscender(true);  
  115.             proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  116.             proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  117.             proinfoCell.setColspan(8);  
  118.             proinfoTab.addCell(proinfoCell);  
  119.   
  120.             proinfoCell = new Cell(new Paragraph("重点评审项目", ST2));  
  121.             proinfoCell.setUseAscender(true);  
  122.             proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  123.             proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  124.             proinfoCell.setColspan(8);  
  125.             proinfoTab.addCell(proinfoCell);  
  126.   
  127.             proinfoCell = new Cell(new Paragraph("序号", ST2));  
  128.             proinfoCell.setUseAscender(true);  
  129.             proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  130.             proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  131.             proinfoTab.addCell(proinfoCell);  
  132.   
  133.             proinfoCell = new Cell(new Paragraph("区县", ST2));  
  134.             proinfoCell.setUseAscender(true);  
  135.             proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  136.             proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  137.             proinfoTab.addCell(proinfoCell);  
  138.   
  139.             proinfoCell = new Cell(new Paragraph("基地名称", ST2));  
  140.             proinfoCell.setUseAscender(true);  
  141.             proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  142.             proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  143.             proinfoTab.addCell(proinfoCell);  
  144.   
  145.             proinfoCell = new Cell(new Paragraph("单位名称", ST2));  
  146.             proinfoCell.setUseAscender(true);  
  147.             proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  148.             proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  149.             proinfoTab.addCell(proinfoCell);  
  150.   
  151.             proinfoCell = new Cell(new Paragraph("基地类别", ST2));  
  152.             proinfoCell.setUseAscender(true);  
  153.             proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  154.             proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  155.             proinfoTab.addCell(proinfoCell);  
  156.   
  157.             proinfoCell = new Cell(new Paragraph("分值", ST2));  
  158.             proinfoCell.setUseAscender(true);  
  159.             proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  160.             proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  161.             proinfoTab.addCell(proinfoCell);  
  162.   
  163.             proinfoCell = new Cell(new Paragraph("等级", ST2));  
  164.             proinfoCell.setUseAscender(true);  
  165.             proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  166.             proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  167.             proinfoTab.addCell(proinfoCell);  
  168.   
  169.             proinfoCell = new Cell(new Paragraph("专家评语", ST2));  
  170.             proinfoCell.setUseAscender(true);  
  171.             proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  172.             proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  173.             proinfoTab.addCell(proinfoCell);  
  174.   
  175.             if (importList.size() > 0 && importList != null) {  
  176.                 for (int i = 0; i < importList.size(); i++) {  
  177.   
  178.                     BBasePoint bbp = (BBasePoint) importList.get(i);  
  179.                     BBaseDocument doc = bbp.getBBaseDocument();  
  180.   
  181.                     // 序号  
  182.                     proinfoCell = new Cell(new Paragraph(String.valueOf(i + 1),  
  183.                             ST));  
  184.                     proinfoCell.setUseAscender(true);  
  185.                     proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  186.                     proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  187.                     proinfoTab.addCell(proinfoCell);  
  188.   
  189.                     // 区县  
  190.                     if (doc.getDocCorpSection() == null) {  
  191.                         proinfoCell = new Cell(new Paragraph("无", ST));  
  192.                     } else {  
  193.                         proinfoCell = new Cell(new Paragraph(doc  
  194.                                 .getDocCorpSection(), ST));  
  195.                     }  
  196.                     proinfoCell.setUseAscender(true);  
  197.                     proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  198.                     proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  199.                     proinfoTab.addCell(proinfoCell);  
  200.   
  201.                     // 基地名称  
  202.                     if (doc.getBaseName() == null) {  
  203.                         proinfoCell = new Cell(new Paragraph("无", ST));  
  204.                     } else {  
  205.                         proinfoCell = new Cell(new Paragraph(doc.getBaseName(),  
  206.                                 ST));  
  207.                     }  
  208.                     proinfoCell.setUseAscender(true);  
  209.                     proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  210.                     proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  211.                     proinfoTab.addCell(proinfoCell);  
  212.   
  213.                     // 单位名称  
  214.                     if (doc.getDocCorpName() == null) {  
  215.                         proinfoCell = new Cell(new Paragraph("无", ST));  
  216.                     } else {  
  217.                         proinfoCell = new Cell(new Paragraph(doc  
  218.                                 .getDocCorpName(), ST));  
  219.                     }  
  220.                     proinfoCell.setUseAscender(true);  
  221.                     proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  222.                     proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  223.                     proinfoTab.addCell(proinfoCell);  
  224.   
  225.                     // 基地类型  
  226.                     if (doc.getDocCorpKind().equals("0")) {  
  227.                         proinfoCell = new Cell(new Paragraph("科普教育基地", ST));  
  228.                     } else if (doc.getDocCorpKind().equals("1")) {  
  229.                         proinfoCell = new Cell(new Paragraph("科普培训基地", ST));  
  230.                     } else if (doc.getDocCorpKind().equals("2")) {  
  231.                         proinfoCell = new Cell(new Paragraph("科普传媒基地", ST));  
  232.                     } else if (doc.getDocCorpKind().equals("3")) {  
  233.                         proinfoCell = new Cell(new Paragraph("科普研发基地", ST));  
  234.                     } else {  
  235.                         proinfoCell = new Cell(new Paragraph("无基地类型", ST));  
  236.                     }  
  237.                     proinfoCell.setUseAscender(true);  
  238.                     proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  239.                     proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  240.                     proinfoTab.addCell(proinfoCell);  
  241.   
  242.                     // 基地评分  
  243.                     if (bbp.getZongpoint() == null) {  
  244.                         proinfoCell = new Cell(new Paragraph("0", ST));  
  245.                     } else {  
  246.                         proinfoCell = new Cell(new Paragraph(String  
  247.                                 .valueOf(Math.round(bbp.getZongpoint())), ST)); // 基地分数  
  248.                     }  
  249.                     proinfoCell.setUseAscender(true);  
  250.                     proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  251.                     proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  252.                     proinfoTab.addCell(proinfoCell);  
  253.   
  254.                     // 分数等级  
  255.                     if (bbp.getGrade() == null) {  
  256.                         proinfoCell = new Cell(new Paragraph("无", ST));  
  257.                     } else {  
  258.                         proinfoCell = new Cell(  
  259.                                 new Paragraph(bbp.getGrade(), ST));  
  260.                     }  
  261.                     proinfoCell.setUseAscender(true);  
  262.                     proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  263.                     proinfoCell.setHorizontalAlignment(Cell.ALIGN_CENTER);  
  264.                     proinfoTab.addCell(proinfoCell);  
  265.   
  266.                     // 专家评语  
  267.                     String opinion = bbp.getOpinion();  
  268.                     if (opinion != null) {  
  269.                         opinion = opinion.replaceAll("<p>""\r\n");  
  270.                         opinion = opinion.replaceAll("</p>""\r\n");  
  271.                         opinion = opinion.replaceAll(" "" ");  
  272.                     } else {  
  273.                         opinion = "无";  
  274.                     }  
  275.                     proinfoCell = new Cell(new Paragraph(opinion, ST));  
  276.                     proinfoCell.setUseAscender(true);  
  277.                     proinfoCell.setVerticalAlignment(Cell.LEFT);  
  278.                     proinfoCell.setHorizontalAlignment(Cell.LEFT);  
  279.                     proinfoTab.addCell(proinfoCell);  
  280.                 }  
  281.             }  
  282.   
  283.             proinfoCell = new Cell(  
  284.                     new Paragraph(  
  285.                             "专 家 签 字:\n\n"  
  286.                                     + "                                                                                                                                           年      月     日\n",  
  287.                             ST));  
  288.             proinfoCell.setUseAscender(true);  
  289.             proinfoCell.setVerticalAlignment(Cell.ALIGN_MIDDLE);  
  290.             proinfoCell.setHorizontalAlignment(Cell.ALIGN_LEFT);  
  291.             proinfoCell.setColspan(8);  
  292.             proinfoTab.addCell(proinfoCell);  
  293.   
  294.             document.add(proinfoTab);  
  295.         } catch (DocumentException de) {  
  296.             System.err.println(de.getMessage());  
  297.             de.printStackTrace();  
  298.         }  
  299.         document.close();  
  300.         return filename + ".pdf";  
  301.     }  
  302. }  


3.downLoad.jsp

  1. <%@ page contentType="text/html;charset=UTF-8" import="com.jspsmart.upload.*" %>  
  2. <%  
  3.   Object obj = request.getAttribute("filepath");  
  4.   String filepath = "";  
  5.   if(obj != null){  
  6.       filepath = (String)obj;  
  7.   }else{  
  8.       filepath = request.getParameter("filepath");  
  9.   }  
  10.   System.out.println("**********"+filepath);  
  11.   //filepath = filepath.replaceAll("/","\\");  
  12.   // 新建一个SmartUpload对象  
  13.   SmartUpload su = new SmartUpload();  
  14.   // 初始化  
  15.   su.initialize(pageContext);  
  16.   su.setContentDisposition(null);  
  17.   // 下载文件  
  18.   su.downloadFile(filepath);  
  19.   out.clear();  
  20. %>  


下面的是在网上看到的一个例子,与大家分享

  1. package com.thuram.test;  
  2.   
  3. import java.awt.Color;  
  4. import java.io.FileOutputStream;  
  5.   
  6. import com.lowagie.text.Cell;  
  7. import com.lowagie.text.Chapter;  
  8. import com.lowagie.text.Document;  
  9. import com.lowagie.text.Font;  
  10. import com.lowagie.text.FontFactory;  
  11. import com.lowagie.text.List;  
  12. import com.lowagie.text.ListItem;  
  13. import com.lowagie.text.PageSize;  
  14. import com.lowagie.text.Paragraph;  
  15. import com.lowagie.text.Section;  
  16. import com.lowagie.text.Table;  
  17. import com.lowagie.text.pdf.PdfWriter;  
  18.   
  19. public class ITextTest ...{  
  20.     public static void main(String[] args) ...{  
  21.         try ...{  
  22.             /** *//** 
  23.              * 首先,创建一个document。 
  24.              * document是PDF文档中所有元素的容器。 
  25.              * 第一个参数表示页的大小,其后的参数分别表示左、右、上、下的边距。 
  26.              */  
  27.             Document document = new Document(PageSize.A4, 50505050);   
  28.               
  29.             /** *//**  
  30.              * 此处创建的write定义了上面创建的document的类型。 
  31.              * 除了PdfWriter以为,还有HtmlWriter, RtfWriter, XmlWriter和一些别的类型。 
  32.              * 第一个参数引用document对象,第二个参数指定了输出文件的绝对路径。 
  33.              * 接着,我们open这个document往里边写入数据。 
  34.              */  
  35.             PdfWriter writer = PdfWriter.getInstance(document,  
  36.                     new FileOutputStream("c:/ITextTest.pdf"));  
  37.             writer.setViewerPreferences(PdfWriter.HideMenubar  
  38.                     | PdfWriter.HideToolbar); // 隐藏菜单栏和工具栏  
  39.             document.open();  
  40.               
  41.             /** *//** 
  42.              * 现在,我们往document的第一页中加入一些文本内容。 
  43.              * 所有的文本都要使用com.lowagie.text.Paragraph才能添加。 
  44.              * 可以创建一个默认的paragraph,使用默认的字体,颜色,尺寸等属性,也可使使用自己定义的字体。 
  45.              * 下面分别进行了这两种操作。 
  46.              */  
  47.             document.add(new Paragraph("First page of the document."));  
  48.             document.add(new Paragraph(  
  49.                             "Some more text on the first page with different color and font type.",  
  50.                             FontFactory.getFont(FontFactory.COURIER, 14,  
  51.                                     Font.BOLD, new Color(255150200))));  
  52.   
  53.             /** *//** 
  54.              * 接下来,我们往document中添加一些复杂的元素。 
  55.              * 让我们从创建一个新的chapter开始。 
  56.              * chapter是一个特殊的部分,它将从新的一页开始,默认显示数字序号。 
  57.              */  
  58.             Paragraph title1 = new Paragraph("Chapter 1", FontFactory.getFont(  
  59.                     FontFactory.HELVETICA, 18, Font.BOLDITALIC, new Color(00,  
  60.                             255)));  
  61.             Chapter chapter1 = new Chapter(title1, 1);   
  62.             chapter1.setNumberDepth(0);   
  63.               
  64.             /** *//** 
  65.              * Section是chapter的一个子元素。 
  66.              * 在下面的代码中我们创建了一个题为"This is Section 1 in Chapter 1" 的Section。 
  67.              * 为了在Section下添加文本,我们再创建一个Paragraph对象,将其增加到Section对象中。 
  68.              */  
  69.             Paragraph title11 = new Paragraph("This is Section 1 in Chapter 1",  
  70.                     FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD,  
  71.                             new Color(25500)));  
  72.             Section section1 = chapter1.addSection(title11);  
  73.             Paragraph someSectionText = new Paragraph(  
  74.                     "This text comes as part of section 1 of chapter 1.");  
  75.             section1.add(someSectionText);  
  76.             someSectionText = new Paragraph("Following is a 3 X 2 table.");  
  77.             section1.add(someSectionText);  
  78.               
  79.             /** *//**  
  80.              * 接着,再创建一个表格(table)对象。 
  81.              * 表格中含有一个行和列的矩阵。 
  82.              * 一行中的单元格(cell)可以延伸到多列。 
  83.              * 同样的,一列中的单元格可以延伸到多行。 
  84.              * 因此,一个3x2的表格不需要6个单元格。 
  85.              */  
  86.             Table t = new Table(32);  
  87.             //设置边框颜色。如果颜色和背景色一样,则边框不会显示出来  
  88.             t.setBorderColor(Color.white);  
  89.             //设置单元格内文本的间距  
  90.             t.setPadding(5);  
  91.             //设置相邻单元格的间距  
  92.             t.setSpacing(5);  
  93.             t.setBorderWidth(1);  
  94.               
  95.             /** *//**  
  96.              * 然后,创建3个单元格对象,包含不同的内容。 
  97.              * 依次将其放入表格中。 
  98.              * 先放在第一行第一列,再放在同一行的下一列中,…… 
  99.              * 当一行填满之后,下一个单元格将放在下一行的第一列中。 
  100.              * 只给定单元格的内容(不新建单元格)也可以新增一个单元格,比如t.addCell("1.1");。 
  101.              * 最后,将表格添加到Section对象中。 
  102.              */  
  103.             Cell c1 = new Cell("Header1");  
  104.             //设置单元格边框颜色,设置方法和表格边框一样  
  105.             c1.setBorderColor(Color.WHITE);  
  106.             t.addCell(c1);  
  107.             c1 = new Cell("Header2");  
  108.             t.addCell(c1);  
  109.             c1 = new Cell("Header3");  
  110.             t.addCell(c1);  
  111.             t.addCell("1.1");  
  112.             t.addCell("1.2");  
  113.             t.addCell("1.3");  
  114.             section1.add(t);  
  115.   
  116.             /** *//** 
  117.              * 接下来,往PDF文档中添加一个列表(List)。 
  118.              * 一个列表包含许多列表项(ListItem)。 
  119.              * 列表可以编号也可以不编号。 
  120.              * 将List的第一个参数置true表示创建的是一个编号的列表; 
  121.              * 第二个参数表示是否使用字母编号,true为使用字母,false为使用数字 
  122.              * 第三个参数为缩进值。 
  123.              */  
  124.             List l = new List(truefalse10);  
  125.             l.add(new ListItem("First item of list"));  
  126.             l.add(new ListItem("Second item of list"));  
  127.             section1.add(l);  
  128.   
  129.             /** *//** 
  130.              * 将chapter放入document中。 
  131.              * 关闭document。 
  132.              */  
  133.             document.add(chapter1);  
  134.             document.close();  
  135.         } catch (Exception e) ...{  
  136.             System.out.println(e.getMessage());  
  137.         }  
  138.     }  
  139. }  

0 0
原创粉丝点击