Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing back to JAR file?

 
Roshni Singhania
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a new query. I have been working on a project, which is working satisfactorily so far. This program needs to read and write data from text files. After finishing the coding, I was trying to package the program as a JAR File. I know how to read data from a text file packaged inside a JAR file, so that was no problem. But I didn't know what to do to WRITE data to the JAR! No such method in the JarFile API, either.

I need to know if there's any way at all to WRITE data back to the file (which is in the JAR). I didn't find anything on google that would help me. On one site, someone said that it might not be possible. I searched this site also. I wasn't able find anything about how to modify a text file within a JAR file. Has anyone ever done this? Is there any way at all to write/modify text files inside the JAR? Any ideas/suggestions are really appreciated. Thanks in advance!
 
Paul Clapham
Sheriff
Posts: 21133
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it's impossible to do that. A JAR file (and a ZIP file) is essentially a read-only archive.
 
Roshni Singhania
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for answering.

So the only way is to carry the required files around, along with the JAR file.. that's the only way I suppose?
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roshni:
So the only way is to carry the required files around, along with the JAR file.. that's the only way I suppose?


Explode the jar on the file system, modify text files and then re-jar.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic