从运行的jar中复制一个文件夹

时间:2016-03-25 14:21:23

标签: java jar fileoutputstream

我找到了一种方法可以帮助我从当前运行的jar中复制一个文件。但我需要复制整个文件夹结构。当我更改输入和输出以匹配我的文件夹时它不起作用

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();
                            }
                        }
                    }

0 个答案:

没有答案
相关问题