标签:
package com.xy;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
public class Test {
/**
* @param args
* @throws FileNotFoundException
* @throws UnsupportedEncodingException
*/
public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
FileInputStream in =null;
InputStreamReader ir =null;
File file = new File(Thread.currentThread().getContextClassLoader().getResource("fileupload.properties").getPath());//获取路径
Properties p = new Properties();
in = new FileInputStream(file);
ir = new InputStreamReader(in, "utf-8");
try {
p.load(ir);
String s = p.getProperty("file.projectLogo");
System.out.println("file.projectLogo得路径读取为"+s);
} catch (IOException e) {
e.printStackTrace();
}
}
}
最后打印的结果为:file.projectLogo得路径读取为D:/upload
其中fileupload.properties文件中配置的file.projectLogo=D\:/upload
标签:
原文地址:http://my.oschina.net/kevin007F/blog/525601