首页 > 编程语言 > 详细

java读取资源文件的方法

时间:2015-11-04 11:40:05      阅读:231      评论:0      收藏:0      [点我收藏+]

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





java读取资源文件的方法

原文:http://my.oschina.net/kevin007F/blog/525601

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!