0

I'm trying to develop a password manager.

My initial thought was to create a file to store the data and Build a jar so that it can be portable.

After searching in google i came to know that we cannot write to a file in the .jar file.

So now is there any other way to develop the application in the way i wanted to (I mean portable jar) ?

sanjay Kumar
  • 140
  • 1
  • 14

2 Answers2

1

Well, you can write to JARs (they are just ZIPs), but this is really not-common. JARs are usually considered to be read-only.

But if you really want to take this approach: I've written some utility classes to work with JARs/ ZIPs based on the NIO.2 File API (the library is Open Source):

Maven:

<dependency>  
    <groupId>org.softsmithy.lib</groupId>  
    <artifactId>softsmithy-lib-core</artifactId>  
    <version>0.4</version>  
</dependency>  

Tutorial:

http://softsmithy.sourceforge.net/lib/current/docs/tutorial/nio-file/index.html

Puce
  • 37,247
  • 13
  • 80
  • 152
-1

JAR files is considered read only, like Program Files folder in windows. So you better left the jar intact, and store the data elsewhere.

If you are developing java desktop application, you can make your application portable by installing the jar to a folder that has write access, and store the data in the same folder as the jar file, ie myprogram.jar and myprogram.dat

Tantowi Mustofa
  • 677
  • 4
  • 8
  • *"Or to make it portable, you can store the data in the same folder as the jar.."* The directory a Jar is stored in: a) Is not available to a JWS launched app. (or any applet). b) Does not necessarily allow write access. The duplicate question I linked shows a path that should be writable, and is easy to discover. -1 – Andrew Thompson Jan 14 '14 at 12:34