Linux path delimiter '/' with the delimiter under Windows ' \ \ ', as well as Java Project, Web project read path to Project

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.