标签:java
代码如下: package com.ryze.work.component; public class MainFrame { // public static final String VERSION_PROPERTIES_FILENAME = "/version.properties"; public static final String VERSION_PROPERTIES_FILENAME = "version.properties"; public static void main(String[] args) throws Exception{ MainFrame mainFrame = new MainFrame(); mainFrame.test(); } public void test(){ java.net.URL versionPropertiesURL = this.getClass().getResource(VERSION_PROPERTIES_FILENAME); System.out.println(versionPropertiesURL); } }运行结果如下:
当用代码 public static final String VERSION_PROPERTIES_FILENAME = "/version.properties"; 替换掉 public static final String VERSION_PROPERTIES_FILENAME = "version.properties";则需要将文件version.properties放到如下路径:
Java学习篇之---getResource()和getResourceAsStream()
标签:java
原文地址:http://blog.csdn.net/a_little_e/article/details/45719295