1, the file delimiter under Linux is '/', and the file delimiter under Windows is ' \ '. But the ' \ ' symbol is an escape character. If you need to output the ' \ ' symbol in the console, you need to enter ' \ \ '. In addition, the escape character ' \ ' can also use double quotation marks inside the character of the double quotation mark again, such as the following third line.
@Test public void test$ () { System.out.println ("\ \"); System.out.println ('/'); System.out.println ("\" in order to escape the double quotation mark \ ""); #分别输出 "\", "/", "in order to escape the double quotation mark" System.out.println ("\") #编译报错 }
Replacement of separators in Linux and Windows environments
The file delimiter under Linux is replaced with the delimiter of window FilePath = filepath.replace ("/", "\ \");
2, get the absolute path to the current project in the Web project:
#tomcat项目获取运行项目的绝对路径String Propath = This.getclass (). GetResource ("/"). GetPath (). substring (1); #例如: Propath = "D:\ Projectname\project_parent\web\target\vsp-web\web-inf\classes "
3, get the current path of the jar in the Java project and read the configuration information under the path where the jar package is located
#java项目打包成jar后, gets the location of the current path to the jar and imports the Config.properties configuration file into the project Properties Prop=new properties (); InputStream in=new FileInputStream (New File (System.getproperty ("User.dir") +file.separator+ "config.properties"); Prop.load (in);
Linux path delimiter '/' with the delimiter under Windows ' \ \ ', as well as Java Project, Web project read path to Project