• Post Reply Bookmark Topic Watch Topic
  • New Topic

Copy File From JAR

 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I have an HTML file residing in my JAR file. I would like to copy it from the JAR file to a place on the hard drive. So far I have worked out choosing the name of the file and where it should be copied. The HTML file is shown in a JTextPane. I do not need to make any modifications to the HTML file. Just need to allow the user to save it anywhere. I am not sure if I need to write the reference f located on the last line.
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know where in the JAR file the HTML file is found, use Class.getResourceAsStream to get a an InputStream to the HTML file. Then simply copy the contents of the InputStream to the FileOutputStream you create for fc.getSelectedFile().
 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Rob Prime. Of course I know where the HTML file resides in the JAR file. I was quite sure this had something to do with InputStream, but was not sure enough to use it, and vesides, it is quite hard to understand. I was able, so far, to get the InputStream part ot work without throwing an exception. More work neeed though. Thanks for the tip. Isaac.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!