Java 获取jar包中工程下的文件路径的问题

package main;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

public class start {

	public static void main(String[] args) throws Exception {
		
		/*File 中可以获取到的路径 jar 中获取不到文件路径*/
		//1、start.class.getResource("../").getPath()+"conf/xconf.xml"
		//2、start.class.getClassLoader().getResource("conf/xconf.xml").getPath()
		//3、File filePath = new File(""); String courseFile = filePath.getCanonicalPath() ;courseFile+"/src/conf/xconf.xml"
		//4、Thread.currentThread().getContextClassLoader().getResource("conf/xconf.xml").getPath()
		//5、new File("./src/conf/xconf.xml").getAbsolutePath()
		//6、"./src/conf/xconf.xml"
		
		Resource res=new Resource();
		String xmlStr = res.getResource(); 
		System.out.println(xmlStr); 
		Map  map = new HashMap();
		
		StringReader sr = new StringReader(xmlStr);
		InputSource is = new InputSource(sr);
		
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();   
		DocumentBuilder builder = factory.newDocumentBuilder();   
		Document doc = builder.parse(is);   
		NodeList nodeList = doc.getElementsByTagName("stor");
		for (int i=0;i

你可能感兴趣的:(Java,开发资料)