Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Renaming a file inside an executable jar file (FILE NOT FOUND!)  RSS feed

 
Inggo Riviera
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I created an executable jar file that I use to update a mysql database. I have a copy of the jar file in a flashdrive which I run it from there. The problem is the default working directory is platform dependent. When I run the jar from the flashdrive using linux I get the file not found exception (there's code that renames a file). Is there a way to point to the flashdrive location in order to rename a file and not the default directory?

Thanks in advance!
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A jar file is not itself a file system and the contents cannot be accessed using File objects.
 
Inggo Riviera
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Was able to access files using getResourceAsStream. Is there a counterpart for outputstream? In windows I can create a file not in the jar but inside the flashdrive, but in linux the default directory is different. Is there a way to control where you want to save a file (to be able to change the working directory)?

tnx.
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no counterpart. You can create a jar file using JarOutputStream so you could copy all the content of the original to a new jar file renaming the file as you go.

I would be interested to know what design decision made this renaming of a jar entry necessary.
 
Inggo Riviera
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James,

Thanks for your help. I'm thinking of a way to run the jar only once. Renaming a file is one way to know if the jar was already run. My runnable jar is located in my flashdrive. If you run it, it would make updates in the DB of the PC. If you have an easier and faster way please let me know.

Thanks!

 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider using the Preferences API to set a flag the first time the program is run.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!