Home » JAVA Programming » Java Basic » Question
  1. How to read a classpath file?
    1. InputStream in =this.getClass().getResourceAsStream(“SomeTextFile.txt”);
    2. InputStream in =this.getClass().getResource(“SomeTextFile.txt”);
    3. InputStream in =this.getClass().getResource(“classpath:/SomeTextFile.txt”);
    4. InputStream in =this.getClass().getResourceClasspath(“SomeTextFile.txt”);
    5. None of these
Correct Option: A

This method can be used to load files using relative path to the package of the class.



Your comments will be displayed only after manual approval.