开发者

Store text files safely in JAR

Is there any way in Java to store external files (inside jar) safely? Java files are compiled to .class files and not readable.

I'm planning to use this meganism to store sql files, whic开发者_JS百科h hold queries, however i dont want those to be readable when one extracts the jar. External files are pre, cause we then have syntax highlighting while developping instead of putting them into a string.


A jar file is pretty much just a .zip file, so you can put whatever you want in them. There's no built-in encryption, so if you're trying to make the SQL files non-readable, you'll have to encrypt them (and then unencrypt in your code). I don't understand what you mean by "External files are pre, cause we then have syntax highlighting while developping instead of putting them into a string."


Yes, people do this all the time. Just add the files to the jar, and then access them with

getResourceAsStream. If you build with maven, you just plop them into src/main/resources to get them into the jar.


Of course you can put them in the Jar. Once there you can get at them by using the ClassLoader's getResourceAsStream method.

The challenge is to prevent other people extracting them. If your code can read them, so can someone else. What are your requirements here?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜