How can an app use files inside the JAR for read and write?

前端 未结 5 775
别那么骄傲
别那么骄傲 2020-11-21 23:09

I need to store data into files inside .jar file and read it again.

I know that I can use Class.getResourceAsStream() method but it returns an Inp

5条回答
  •  时光取名叫无心
    2020-11-22 00:01

    I need to store data into files inside .jar file and read it again

    No you don't.

    Instead store the 'default' file inside the Jar. If it is changed, store the altered file in another place. One common place is a sub-directory of user.home. When checking for the file, first check the existence of an altered file on the file system, and if it does not exist, load the default file.


    Note that it is generally better to describe the goal, rather than the strategy. 'Store changed file in Jar' is a strategy, whereas 'Save preferences between runs' might be the goal.

    Related: What is the XY problem?

提交回复
热议问题