In Java, should resources be placed in the package / source hierarchy?

Suppose I develop a game and put it into the package structure:

com.dxmio.games.breakout

So where is the "best practice" place to place resources such as audio and images used by the game?

Solution

I have seen that there are many ways to deal with this:

>Put your resources directly in a subdirectory COM / dmxio / Games / breakout (for example, / COM / dmxio / Games / breakout / images / foo. GIF and / COM / dmxio / Games / breakout / images / bar. GIF) > put your resources in a jar and bind them with your class files (for example, foo.gif and bar.gif are bundled in breakout. Jar) >Place resources jar in a subdirectory under COM / dmxio / Games / breakout (for example, foo.gif and bar.gif are bundled together / COM / dmxio / Games / breakout / images / images. Jar)

I prefer to support the last option

You can then use Java lang.Class. The getresource () method retrieves the resource

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>