Get the root directory of the current class ( namely classpath, Such as bin、classes、AppName etc. ) There are :

1、Thread.currentThread().getContextClassLoader().getResource("").getPath()

2、ClassLoader.getSystemClassLoader().getResource("").getPath()

3、XX.class.getResource("/").getPath(), Pay attention to this /, Otherwise, it will be specific to a certain bag instead of classes Catalog , There can't be / Otherwise, the report will be wrong

notes : use System.getProperty("user.dir") The way to webapp It's not desirable for us .

obtain webapp Of WEB-INF You can use :this.getServletContext().getRealPath("/").concat("WEB-INF/")

To get the configuration file, you can use :Thread.currentThread().getContextClassLoader().getResourceAsStream("db.properties")

, Note that this method cannot be used to obtain information such as .java Otherwise, it will report an error ( The reason for the error should be URLClassPath Of the inner class FileLoader stay getResource in check They found .java It's a suffix that's not allowed, so it's an exception return null, It was used 5 None of the decompilers were decompiled ).

Java More articles on fragmentary summary

  1. java Bits and pieces of knowledge

    1. Strings have integer conversions 1 2 String a = String.valueOf(2);   //integer to numeric string  int i = Integer.pars ...

  2. java Fragmentary 1

    1. java The entry to the program must be static Type of , No... Is allowed in the interface static , And the method in the interface must be public. 2. java Recycling is mainly aimed at the recovery of the heap area . 3. java.exe yes ...

  3. Java Bits and pieces of knowledge

    █    for instance :Iterator iter = map.entrySet().iterator(); xx.yy() , It means a xx Object's yy Method ,xx.yy().zz() in xx.yy() return ...

  4. java Bits and pieces of knowledge ( Default values for each data type , How big? , Value range )

    Just write down the bytes You don't have to memorize anything else , Value range : There is no positive or negative ,2 Of Number of bytes *8 Power -1  , Whatever has positive or negative 2 Of ( Number of bytes *8)-1 Power -1 such as : 1.byte( There are positive and negative ): First of all, the calculation is 2 Several power : Number of bytes 1*( ...

  5. Spark case analysis

    One . demand : Calculate the top three page views import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  6. Further exploration java Basics —— Sorting out the basic knowledge

    1.java It's interpreted language .java The virtual machine can compile and run many times at a time . 2.JDK(java software Development kit  Software development package ),JRE(java Runtime Environ ...

  7. java Way of learning -- Fragmentary knowledge notes

    java Operator : Auto increment and auto decrement operator : int b = ++a; The process of splitting operation is : a=a+1=4; b=a=4, The final result is b=4,a=4  Prefix increment and subtraction (++a,--a): First, add or subtract , Again ...

  8. Theory Chapter -Java Some fragmentary knowledge points in the book

    1. Java in length,length Method ,size Method difference length attribute : Used to get the array length . length Method : Used to get the string length . size Method : Used to get how many elements there are in a generic collection . 2. is ...

  9. 【java】 Some fragmentary knowledge points

    java Annotation document Some commonly used javadoc label Commonly used javadoc label @see: other-class quote other-class Generated html The document will have a See Alse As hyperlinks, it's just items ...

Random recommendation

  1. Web Report tool FineReport Of JS The string of development

    In the report development process , Some requirements may not be realized through existing functions , Second development by developers is needed , With FineReport For example , You can use web script .API Interface, etc . in consideration of JS Script development is widely used , Here's Jane first ...

  2. Java — JTree and JTable as well as sqlServer There are two kinds of connections

    Use JTree Steps for : Only one head node can be created for the time being , Create a tree node as the head node ( Its child nodes are created in the same way ):DefaultMutableTreeNode headNode = new DefaultMu ...

  3. FileInputStream and FileOutputStream

    Java FileOutputStream class Java FileOutputStream is an output stream for writing data to a file. If ...

  4. 【Spring actual combat 】--1Spring At the heart of

    Recent interviews always involve Spring The advantages of ,SpringMVC And Struts2 Comparison , Life slowly stabilizes , These interviews still answer that sentence “ Just blindly pull the car , I don't look down at the road ”, In retrospect, we should study it carefully Spring, If it's just ...

  5. Oral English practice series -C22- Eat something

    Basic vocabulary 1. bill [bɪl] n. bill : Bank note : bill : beak Bill ( The person's name ) bill pay the bill Pay the bill telephone bill Bill electricity bill electric ...

  6. jquery Source code interpretation

    I've been studying jQuery Source code , At first glance, the source code is confused and confused , It's really wonderful to really calm down and read it carefully , Its structure is clear , High cohesion . Low coupling , Excellent performance and convenient scalability , Browser compatibility ( Functional defects . Progressive enhancement ) Elegant handling can ...

  7. pycharm2018 Crack

    1. download   link :https://pan.baidu.com/s/1G0C9xoUQg6JRgNQYLMIi1w password :2z3x 2. modify  "G:\Python\JetBrains\PyCha ...

  8. SQL There are three types of submitted data

    Insert in database . When deleting and modifying operations , Only when the transaction is committed to the database can it be completed . SQL There are three types of statement commit data : Explicitly commit . Implicit and automatic submission . [1] Explicitly commit Explicitly commit . The box COMMIT Command to complete the submission directly . ...

  9. graphql Data import tool

    graphql It's better than A more convenient tool , But data import is also an important tool prisma Contains a seed The function of , similar docker We use mysql Database initdb.d, But that's basically It's Tim ...

  10. Error: Exception was raised when calling event-notify Vuser function in extension parameng.dll: System Exceptions: EXCEPTION_ACCESS_VIOLATION

    resolvent : stay C Create a new TEMP Catalog , Put environment variables TMP,TEMP Set the value of to the environment variable , Restart the computer