1 through the class loader loader,
1. URL resource = TestMain.class.getResource ("/18500228040.txt");
File File = new file (Resource.getfile ());
String Absolutepath = File.getabsolutepath ();
This way the absolute path is obtained, window and Linux will get different results, and these will be in the editor to run the program in the time can be successful, but once the jar package, it will create a problem
The reaction under Window
There's a reaction like this on Linux.
2. String Path = This.getclass (). GetResource ("/18500228040.txt"). GetPath (); and by this way the load is the same as above, But this will get the absolute path relative to the drive letter below the window, but note that a "/" will be added to the front of him, causing the path to be found when the resource is not available.
By intercepting the right results, it is not a good solution, will continue to do research, then will be written on the blog
Maven project, Java code load resources below the resource file path