java读取配置文件

1,java读取.properties配置文件
InputStream in;
		try {
			in = test.class.getClassLoader().getResourceAsStream("config/ipnetOracle.properties");//配置文件的路径
		    Properties p = new Properties();
			p.load(in);
			String a = p.getProperty("chirdSystem");//chirdSystem为配置文件中的key
			System.out.println(a);
		} catch (IOException e) {
			e.printStackTrace();
		}

2,java读取.xml配置文件
 File f = new File("data.xml");

  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

  DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(f);
   NodeList nl = doc.getElementsByTagName("VALUE");
   for (int i = 0; i < nl.getLength(); i++) {
    System.out.print("号码:"+ doc.getElementsByTagName("NO").item(i).getFirstChild().getNodeValue());

  System.out.println("地址:"+ doc.getElementsByTagName("ADDR").item(i).getFirstChild().getNodeValue());

你可能感兴趣的