一不小心用这个代码创建了N多的C文件夹,太多了都删不掉了。怎么才能删。一直没找到方法,里面的文件倒是全删了,文件夹不知道怎么去删。
import java.io.*;
public class server
{
public static void main(String args[]) throws IOException
{
String url1 = "D:\\a";
String url2 = "D:\\a\\c";
copyDirectiory(url2 , url1 );
}
public static void copyDirectiory(String s1, String s2) throws IOException
{
(new File(s1)).mkdirs();
File[] file = (new File(s2)).listFiles();
for (int i = 0; i < file.length; i++)
{
if (file[i].isFile())
{
FileInputStream aj = new FileInputStream(file[i]);
FileOutputStream ag = new FileOutputStream(s1 + "\\" + file[i].getName());
byte[] b = new byte[1024 ];
int len;
while ((len = aj.read(b)) != -1)
{
ag.write(b, 0, len);
}
ag.close();
aj.close();
}
if (file[i].isDirectory())
{
copyDirectiory(s1 + "\\" + file[i].getName(), s2 + "\\" + file[i].getName());
}
}
}
}
|
|