Java Resource file Interpretation

Source: Internet
Author: User

"1" Construction works from scratch

The simplest: Http://www.cnblogs.com/alipayhutu

where d) in exchange for:

ApplicationContext context = new Classpathxmlapplicationcontext ("config +");
Main main = (main) Context.getbean ("main");

For more information, refer to: http://hi.baidu.com/shutaodream/blog/item/a51b9f1bf1da00b94aedbcd0.html

"2" Eclipse, Project/file directory

1. Get the system root directory

    • System.getproperty ("User.home");
    • such as output, C:\Users\hutu

2. Get the Project Catalog

    • System.getproperty ("User.dir");
    • such as output, D:\workspaces\workspace1\myProject

3. New file, default in project directory

    • New File ("Xxx.txt"). GetAbsolutePath ();
    • such as output, D:\workspaces\workspace1\myProject

4. Configuration file path

    • ApplicationContext context = new Classpathxmlapplicationcontext ("config +");
      1. . XML,. Properties, etc., by default or from the "Engineering catalog" to find

1). can also use absolute path, really not recommended Ah, too not elegant;

2). Alternatively, place the log4j file in the bin/directory:

a). In the Code, Propertyconfigurator.configure ("bin/log4j.properties");

b). In the Code, propertyconfigurator.configure (classloader.getsystemresource("log4j.properties"));

c). Note that it must be located in the bin Direct directory and not in the deeper directory of the bin. But is this a god-horse pinch?

5. Query the directory where the. class files for a class

    • Main.class.getResource ("");
    • For example output, D:\workspaces\workspace1\myProject\bin\com\hutu\log4j\
    • Note that querying the package ancestor path simply changes the parameter to "/"

6. Query the directory where the thread context resides

    • Thread.CurrentThread (). Getcontextclassloader (). GetResource ("");
    • such as output, D:\workspaces\workspace1\myProject\bin\

7. Query the directory where the ClassLoader of a class

    • Main.class.getClassLoader (). GetResource ("");
    • such as output, D:\workspaces\workspace1\myProject\bin\

8. Query the directory where ClassLoader is located

      • Classloader.getsystemresource ("");
      • such as output, D:\workspaces\workspace1\myProject\bin\

Interpreting Java Resource files

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.