查看类加载的文件路径

public static void main(String[] args) {
 	String oldFilePaths="C:\\Users\\hui\\Desktop\\resume.docx";
 	String newFilePaths="C:\\Users\\hui\\Desktop\\个人简历表格new2.docx";
		OutputStream out=null;
		XWPFDocument document=null;
		try {
			Map<String , String> orgMap=new HashMap<String , String>();
			orgMap.put("obj_Name", "张三");
			ClassLoader classloader =  
			 org.apache.poi.poifs.filesystem.POIFSFileSystem.class.getClassLoader();  
			URL res = classloader.getResource(  
				 "org/apache/poi/poifs/filesystem/POIFSFileSystem.class");  
			String path = res.getPath();  
			System.out.println("POI Core came from " + path);  
					  
			classloader = org.apache.poi.POIXMLDocument.class.getClassLoader();  
			res = classloader.getResource("org/apache/poi/POIXMLDocument.class");  
			path = res.getPath();  
			System.out.println("POI OOXML came from " + path);  
					  
			classloader = org.apache.poi.xwpf.usermodel.XWPFDocument.class.getClassLoader();
			res = classloader.getResource("org/apache/poi/xwpf/usermodel/XWPFDocument.class");  
			path = res.getPath();  
			System.out.println("POI Scratchpad came from " + path);  
			document=new XWPFDocument(POIXMLDocument.openPackage(oldFilePaths));
 			System.out.println(document.getTables().size());
 			for (XWPFTable tables : document.getTables()) {
 				for (XWPFTableRow row : tables.getRows()) {
						for (XWPFTableCell cell : row.getTableCells()) {
							System.out.println(cell.getText());
						}
				}
			}
			replaceTable(document, orgMap);
			out=new FileOutputStream(new File(newFilePaths));
			document.write(out);
			out.close();
		} catch (IOException e) {
				if (out !=null) {
					try {
						out.close();
					} catch (IOException e1) {
						e1.printStackTrace();
					}
				}
			e.printStackTrace();
		}finally {
			if (out !=null) {
				try {
					out.close();
				} catch (IOException e1) {
					e1.printStackTrace();
				}
			}
		}
		
	}

输出结果

POI Core came from file:/E:/03.WorkSpaceToNew/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/rssp.social.web/WEB-INF/lib/poi-3.17.jar!/org/apache/poi/poifs/filesystem/POIFSFileSystem.class
POI OOXML came from file:/E:/03.WorkSpaceToNew/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/rssp.social.web/WEB-INF/lib/poi-ooxml-3.17.jar!/org/apache/poi/POIXMLDocument.class
POI Scratchpad came from file:/E:/03.WorkSpaceToNew/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/rssp.social.web/WEB-INF/lib/poi-ooxml-3.17.jar!/org/apache/poi/xwpf/usermodel

 

转载于:https://my.oschina.net/u/3406827/blog/1585555

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值