0

I have found a method that helps me copying one file out of my current running jar. But i need to copy the whole folder structur. When I change the Input and Output to match my Folder its not working

InputStream stream = Main.class
                        .getClassLoader().getResourceAsStream("res/szenario/home.html");
                    FileOutputStream fos = null;
                    try {
                        fos = new FileOutputStream("home.html");
                        byte[] buf = new byte[2048];
                        int r = stream.read(buf);
                        while(r != -1) {
                            fos.write(buf, 0, r);
                            r = stream.read(buf);
                        }
                    } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } finally {
                        if(fos != null) {
                            try {
                                fos.close();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }
  • Possible duplicate of [Copy directory from a jar file](http://stackoverflow.com/questions/1386809/copy-directory-from-a-jar-file) – mguymon Mar 25 '16 at 14:25
  • You need to copy the files recursively from the folder. One approach would be to use ```FileUtils.copyDirectory()```. Just remember the input and output are supposed to be directories. – dambros Mar 25 '16 at 14:27
  • a) What exactly is not working? b) Note that a zip/jar file does not know anything about folders. It just contains files that happen to have `/` or `\` in their names. – Harald Mar 25 '16 at 14:34

0 Answers0