Android studio 读取properties文件

System.out.println(Thread.currentThread().getContextClassLoader().getResource("").getPath());
获取的路径是:
workSpace/Project_name/Module_name/build/classes/main/

第一:设置project视图

第二:在src目录的main目录创建相应的文件夹resources和properties文件

 

 

运行main()后,会在 build 输出相应的文件夹

 

第三:读取properties文件,输出测试

摘要:Thread.currentThread().getContextClassLoader().getResourceAsStream("abc.properties")  获取输入流

InputStream in=new BufferedInputStream(Thread.currentThread()
.getContextClassLoader().getResourceAsStream("abc.properties"));
byte[] flush=new byte[1024];
int len=0;
StringBuilder builder=new StringBuilder();
while(-1!=(len=in.read(flush))){
builder.append(new String(flush,0,len));
}
in.close();
System.out.println(builder.toString());

 

posted on 2016-08-25 10:03  无畏2020  阅读(1447)  评论(0)    收藏  举报

导航