when i tried with that it is copying the empty direcory but not all its subdirectories.iam sending my program also
import java.io.*;
public class copy
{
private void copyFile(File src, File dst) throws IOException
{
InputStream in = new FileInputStream(src);
OutputStream out = 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();
}
public int copyDirectory(File srcDir, File dstDir) throws IOException
{
if (srcDir.isDirectory())
{
if (!dstDir.exists())
{
dstDir.mkdir();
}
String[] children = srcDir.list();
int c= children.length;
System.out.println(c);
for (int i = 0; i < children.length; i++) {
copyDirectory(new File(srcDir, children[i]),
new File(dstDir, children[i]));
}
}
else {
// This method is implemented in e1071 Copying a File
copyFile(srcDir, dstDir);
}
return 1;
};
public static void main(String args[]) throws IOException {
copy c = new copy();
c.copyDirectory(new File("d:/raj/sub "),new File("d:/sub"));
c.copyFile(new File("d:/raj/sub/auth.html"),new File("d:/sub/auth.html")) ;
}
}
pleaase help me how to resolve this problem