getResourceAsStream returns NULL

After compilation, the config.propertes configuration file is generated in the target/classes directory.

This configuration file is used in the A class in the code. The usage is as follows:

prop.load(Object.class.getResourceAsStream("/config.properties"));

The result has been reported a NULL error.

Print path view

System.out.println(Object.class.getResource("/"));

The result is NULL, and the print path

System.out.println(A.class.getResource("/"));

The result is target/classes/

Therefore, the statement that takes the attribute is replaced.

prop.load(A.class.getResourceAsStream("/config.properties"));

 

Intelligent Recommendation

getResource and getResourceAsStream take the value null; java music loop play

I wanted to implement music loop playback in a java application, but the return value of getResource("music/bg.wav") is null. I guess the path is a problem. I tried tryResource("/music/...

DAO factory design and implementation class.getClassLoader (). GetResourceAsStream () is null solution

To avoid coupling code, DAO layer using the factory pattern is achieved. 1. Write a profile daoconfig.properties, here is my own employee of a table 2.DAO Interface: Define methods 3.DAO JDBC interfac...

Maven: Using Class.GetClassLoader (). GetResourceAsStream () triggers an exception instream parameter is null

Today, I used Spring to create a web project. I used Maven when I could create a Spring project. It is very convenient to use the Maven House. It is only a bug in today. Source code: Discover is jdbcu...

Android project custom profile to resolve getResourceAsStream () Return null

Returns NULL is the path error. After multiple attempts, use the following method to solve 1. Create an Assets folder, create a new config.properties file 2.config.properties file content 3. Create a ...

javaWeb project class.getClassLoader().getResourceAsStream gets the result as null solution

When learning a Web project, I encountered a simple problem and recorded the solution. I am taking a Java course from Dark Horse Programmer. The course was taken in May 2018. The current IDEA is a lit...

More Recommendation

Regarding the question of class.getClassLoader().getResourceAsStream() is null under the Maven project

Regarding the question of class.getClassLoader().getResourceAsStream() is null under the Maven project Recently I used this method in a Java project. In the copy to library project, I found that the r...

getLastKnownLocation() returns a null solution

always uses the LocationManager.getLastKnownLocation("gps") to get the gps location. Baidu checked a lot of information on the Internet and found that this problem appeared in version 2.0 or...

SelectionKey.attachment() returns null

When I wrote the NIO program, I encountered the problem that the SelectionKey.attachment() was empty. Finally, I solved it. Here, I would like to help others:    ...

UDF unexpectedly returns null

background Today I wrote a UDF function to calculate the parameters of the fan interaction rate. When there is a video number, the interaction_sum is divided by the number of videos, otherwise divided...

BitmapFactory.decodeResource returns null question

Question code: Bitmap bmp = BitmapFactory.decodeResource(resources, R.drawable.ic_image); among them R.drawable.ic_image , this code is at4.4 Running fine, but in5.0 The above system will have a null ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top