刚刚学了IO,老师留了一些作业。同学想copy我的,又不好意思不给
于是想用File写个n层文件夹(n>5000) 然后把程序放在底层给他们
同时输出CDKey。txt为文件夹底层路径 方便自己管理
为了防止别人使用粘贴复制来叠加路径 所以使用的是随机文件名所有的设想就是这样程序也很简单import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2006-11-14
 * Time: 3:12:08
 * To change this template use File | Settings | File Templates.
 */
public class JokeDir {
    public static void main(String[] args) throws IOException {
        String strPath = "C:\\Documents and Settings\\Administrator\\桌面";
        for (int i = 0; i < 5000; i++) {
            int num = (int) (Math.random() * 1000);
            strPath = strPath + "\\" + Integer.toString(num);
            File f = new File(strPath);
            f.mkdir();
        }
        BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\Documents and Settings\\Administrator\\桌面\\CDKey.txt"));
        bw.write(strPath);
        bw.close();
    }
}之后就很郁闷了,先不说因为路径名太长而无法访问底层文件夹
就是想删除这个文件夹都不可能,从DOS下都不可以...
文件可以剪切,但是无法剪切到U盘有兴趣的话大家可以试试,并想想办法PS。有趣的是,这个无限文件夹可以打包成rar
只要在别电脑上一解压缩,那么这个文件夹就钉在那台电脑上了
我忽然想到可以做一个批处理,在别人的电脑上运行,让他们的桌面铺满删不掉的文件夹

解决方案 »

  1.   

    http://photo.bababian.com/20061114/03359668001DC24857C15C7B13F6E2FD_500.jpg
    http://photo.bababian.com/20061114/2A399F85BEDF46AC445BF2ADBC83F029_500.jpg以上是问题相关图片
      

  2.   

    5000层,cpu与内存够呛。p.s. 楼主思想不健康!不想让同学抄袭劳动成果,直说好了,玩这种小花招。再说楼主也知道批处理,如果这5000层能访问,相信一个批处理就能将里面文件拷出来。
      

  3.   

    找一个把目录映射成盘符的工具,如FolderToDrive一类的东西,然后把你能够访问到的最深层的目录
    映射成盘符,比如E,然后在E下面找到能够访问到的最深层的目录再映射成盘符F,这样重复几次就可
    以删除了,当然删除的时候是从最后一个盘符进行的。祝你好运!
      

  4.   

    阴险狡诈狠毒毒辣!
    CSDN是一个人才辈出的地方!
    哈哈~
    我当年上学的时候最鄙视小气不给我作业抄的同学了!
      

  5.   

    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;public class JokeDir {
    public static void main(String[] args){
    String strPath = "D:\\jokedir";
    for (int i = 0; i < 5000; i++) {
    int num = (int) (Math.random() * 1000);
    strPath = strPath + "\\" + Integer.toString(num);
    File f = new File(strPath);
    f.mkdirs();
    }

    BufferedWriter bw;
    try {
    bw = new BufferedWriter(new FileWriter("D:\\cdkey.txt"));
    bw.write(strPath + "\\test.txt");
    bw.close();
    } catch (IOException e) {
    e.printStackTrace();
    }

    //delFolder(D:\\jokedir);
    } public static void delFolder(String folderPath) {
    try {
    delAllFile(folderPath);
    String filePath = folderPath;
    filePath = filePath.toString();
    java.io.File myFilePath = new java.io.File(filePath);
    myFilePath.delete();
    } catch (Exception e) {
    e.printStackTrace();
    }
    } public static boolean delAllFile(String path) {
    boolean bea = false;
    File file = new File(path);
    if (!file.exists()) {
    return bea;
    }
    if (!file.isDirectory()) {
    return bea;
    }
    String[] tempList = file.list();
    File temp = null;
    for (int i = 0; i < tempList.length; i++) {
    if (path.endsWith(File.separator)) {
    temp = new File(path + tempList[i]);
    } else {
    temp = new File(path + File.separator + tempList[i]);
    }
    if (temp.isFile()) {
    temp.delete();
    }
    if (temp.isDirectory()) {
    delAllFile(path + "/" + tempList[i]);
    delFolder(path + "/" + tempList[i]);
    bea = true;
    }
    }
    return bea;
    }
    }
    加了两个递归删除文件夹的方法,试验过好用,请楼主引以为戒,不要再做这等事情了,个人意见,仅供参考。
      

  6.   

    //delFolder(D:\\jokedir);
    将这句解除注释,并将参数用引号括起。
      

  7.   

    谢谢楼上的这位兄台了代码写得好严禁并且唤起了我解决这个问题的勇气毕竟是我自己惹的麻烦不过现在好了有了“流氓文件夹”现在也有了“专杀工具”一切就可以在可控的条件下进行了我觉得还是可以用这个程序稍微干点“别的”至少对我来说 可以大大激发初学者学习java的兴趣嘛^_^我自己也写了一个“专杀”不过没有楼上的严谨只是看起来稍微简单一些import java.io.File;/**
     * Created by IntelliJ IDEA.
     * User: Administrator
     * Date: 2006-11-15
     * Time: 4:00:01
     * To change this template use File | Settings | File Templates.
     */
    public class DeleteJokeDir {
        static int i=0;
        public static void main(String[] args) {
            String strPath = "C:\\Documents and Settings\\Administrator\\桌面\\obj";
            deleteDir(strPath);
        }    static void deleteDir(String strPath) {
            File f = new File(strPath);
            if(f.list().length!=0){
                System.out.println("DOWN"+i++);
                deleteDir(strPath+"\\"+f.list()[0]);
            }
            f.delete();
            System.out.println("UP"+i--);
        }
    }