English 中文(简体)
• 如何收回财富?
原标题:How to retrieve .properties?

Im developing desktop java application using maven. I got a *.properties file that I need to retrive during execution (src/resources/application.properties). The only thing comes to my mind is to use:

private Properties applicationProperties;
applicationProperties.load(new BufferedInputStream(new FileInputStream("src/resources/application.properties")));

This would work if I run my application directly from IDE. I want to to keep outpout hierarchy clear, so I set maven to copy resources folder dircetly to target folder (which is a basedir for the output application). This way application.properties file won t load (since I have target/resources/application.properties but not target/src/resources/application.properties).

在我从民主选举学会中解答并直接建立杰尔档案时,管理资源的最佳方式是什么?

最佳回答

Don t 预计文档将载于src 倍数——在运行时间确实没有。 财产档案上/bin。 但这也不依赖。 由于<代码>FileInputStream仅采用绝对途径。

当你需要一种同堂关系的道路时,使用:

InputStream is = YourClass.class.getResourceAsStream("/a.properties")`

(maven将文档从/src/main/resources发送至各年级的根基)

问题回答

您应当把财产档案从产阶级而不是从明确的档案系统地点上载:

 applicationProperties.load(new BufferedInputStream(this.getClass().getResourceAsStream( "/application.properties" );

只要您的民主选举学会将资源目录配置到您的班次上(这应该是Maven的缺省),那么,这就会有助于你是否在民主选举学会内部重新运作,或者因为晚会把资源复制到适当的地方,把你们的档案整理起来。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签