A two effects:
在java中加载文件
II. Difference between the two
-
. .GetClass () getResource (fileName): fileName represents only looks for the file in the same directory where the current call class;
-
.. .GetClass () getClassLoader () getResource (fileName): represents only find the file in the root directory (/);
-
fileName if it is preceded by "/", such as "/ fileName", said absolute path, taken / the files in the directory;
if it is not preceded by "/", such as "fileName" indicates a relative path, taking the call the files in the same class path. -
If the path name contains the package, getClass () getResource ( "com / xxx / 1.xml");.
Hierarchy using the package name "/" spaced (forward slash), rather than "."