• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Copy File From JAR

 
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22650
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Forget Steve. Look at this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic