以下格式都是正确的(注意:.properties文件中的第一行不要有空格!):

idea 获取resources资源目录下文件-LMLPHP

        URL resource01 = MainMobile.class.getResource("");
URL resource02 = MainMobile.class.getResource("/conf.properties");//success: resources下的 InputStream ip3 = MainMobile.class.getClassLoader().getResourceAsStream("conf.properties");//success: resources下的
InputStream resource32 = Thread.currentThread().getContextClassLoader().getResourceAsStream("conf.properties"); InputStream ips = MainMobile.class.getResourceAsStream("/conf.properties");//success: resources下的
URL resource13 = Thread.currentThread().getContextClassLoader().getResource("conf.properties");
InputStream resource43 = Thread.currentThread().getContextClassLoader().getResourceAsStream("conf.properties");
InputStream resource23 = Thread.currentThread().getContextClassLoader().getResourceAsStream("conf.properties");
05-18 21:27