public void copyDirectory(File srcDir, File dstDir) throws IOException {
String[] children = srcDir.list();
for (int i=0; i<children.length; i++) {
copyFile(new File(srcDir, children[i]),
new File(dstDir, children[i]));
}
}
void copyFile(File src, File dst) throws IOException {
InputStream in = new BufferedInputStream(new FileInputStream(src));
OutputStream out = new BufferedOutputStream( new FileOutputStream(dst));
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
Above code is working fine in simple
java file,but not in servlet.
OutputStream out = new BufferedOutputStream( new FileOutputStream(dst)); : At this line,control gets hanged and not going further.
If i write same code in
JSP, file is getting created successfully, but it is created in OC4J/bin directory.
We are using OC4J application server.
From servlet, i want to create file at location from where it is accessible by jsp.
Please let me know, how can we do that.