lusyoe
V2EX  ›  Android

Android Studio 使用普通类加载读取 properties 配置文件,应该放在哪个目录?

  •  
  •   lusyoe · Jan 12, 2015 · 19194 views
    This topic created in 4169 days ago, the information mentioned may be changed or developed.

    大家好,我才刚开始使用Android Studio,目前是用1.0.2版本,最近在项目中要使用工厂设计模式,要在工厂类的静态代码块中加载properties配置文件。以前在eclipse中我一般都是直接放在src目录下,这样就可以直接加载了。但在AS中我发现,并不能正确的读取,每次都是返回null。。
    我尝试了百度,google,只搜到说要放在classPath中,但AS中我并不能找到准确的路径。
    最后,实在无奈下,我将配置文件打包成jar包,然后再放在libs目录下,才可以正确的读取了。但是每次要修改又得从新打包,太麻烦了。
    请教下各位,你们都是放在哪个目录下可以正确加载读取的??

    3 replies    2015-01-30 00:42:38 +08:00
    shunia
        1
    shunia  
       Jan 15, 2015
    放到res/raw/下
    properties.load(getResources().openRawResource(R.raw.yourPropertiesFileName));
    zgxltxz
        2
    zgxltxz  
       Jan 27, 2015 via Android
    assets下的东西不会被编译
    lusyoe
        3
    lusyoe  
    OP
       Jan 30, 2015
    @shunia 如果是一个普通类可以调用getResources()??,我是通过类加载器读取的。BeanFactory.class.getClassLoader().getResourceAsStream(FileName);
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3130 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 08:13 · PVG 16:13 · LAX 01:13 · JFK 04:13
    ♥ Do have faith in what you're doing.