Java programs, there are two ways to read resource operations.
The first is directly through file. such as FileReader, BufferedReader and so on. The file directory is relative to project. If I create a new MyProject, then, I have a icons folder under MyProject, if you want to read icons inside, the path is a relative path such as "Icons/***.gif" can be.
The second is obtained by GetClass (). GetResource (""). The second method must ensure that the file is under the path included in the classpath. The General Classpath (a. classpath file that can view any Eclipse project) includes at least the following:
<?xml version= "1.0" encoding= "UTF-8"?>
<classpath>
<classpathentry kind= "src" path= "src"/>
<classpathentry kind= "Con" path= "org.eclipse.jdt.launching.jre_container/ Org.eclipse.jdt.internal.debug.ui.launcher.standardvmtype/jdk1.7.0_51 "/>
<classpathentry kind= "Output" path= "Bin"/>
</classpath〉
The src and bin are the default, so the second way, the resource file must be under both folders. So if there is a Property.ini file under the SRC folder, it can be obtained by getresource ("/property.ini"), Note that this must start with '/' .
Maven project, the default has a resource folder, and this folder is under the Classpath path, so generally put the resource files here, and then conveniently through the getresource () to get the content.
And for xxx=xxx This configuration information, Java specifically designed a class to handle, ResourceBundle. The general processing method is as follows,
ResourceBundle resource = Resourcebundle.getbundle ("Conf/a.txt");
propertyResourceBundle bundle = (propertyresourcebundle) bundle;
enumeration<string> keys = Bundle.keys ();
for (String Key:keys)
{
Solve Bundle.getstring (key)
}
How the path is specified when a Java program reads a resource file