最近碰到一个问题在linux系统下发现可以建立这样的文件夹名称是"f:\qqq",通过java备份该目录到另外一个目录下,当遇到这个的文件名称的时候,获取该文件的绝对路径只能获取到"f:", "\"之后的内容获取不到,导致提示备份的文件路径找不到。请各位大侠指点。     if(sourceFile.isFile()) {
     String sourcepath = sourceFile.getAbsolutePath();
     source.add(sourcepath);
     String destpath = destDir + "/" + sourcepath.substring(sourcepath.indexOf(sourceDir) + sourceDir.length());
     dest.add(destpath);
    
     }

解决方案 »

  1.   

     /** 
         * @param sourcePath 
         *            要备份的目录 
         * @param aimPath 
         *            存放备份的目录 
         * @param filtDir 
         *            要过滤的目录列表 
         * @param filtFiles 
         *            要过滤的文件列表 
         * @param actionType 
         *            执行备份类型 1:GZIP压缩方式,非1值为拷贝 
         * @throws Exception 
         */  
        public static void backup(String sourcePath, String aimPath,  
                List<String> filtDir, List<String> filtFiles, int actionType)  
                throws Exception {  
            SimpleDateFormat dateFormat = new SimpleDateFormat(  
                    "yyyy-MM-dd-hh-mm-ss");  
            String datePath = dateFormat.format(new Date());  
            switch (actionType) {  
            case 1:  
                aimPath = buildPath(aimPath);  
                OutputStream os = new FileOutputStream(aimPath + datePath + ".zip");  
                BufferedOutputStream bs = new BufferedOutputStream(os);  
                ZipOutputStream zo = new ZipOutputStream(bs);  
                deepGzipDir(sourcePath, sourcePath, zo, filtDir, filtFiles);  
                zo.closeEntry();  
                zo.close();  
                break;  
            default:  
                deepCopyDir(sourcePath, aimPath + "/" + datePath + "/", filtDir,  
                        filtFiles);  
                break;  
            }  
        }  
      

  2.   

    楼上给的处理办法不能处理这个问题吧。                deepGzipDir(files[i].getPath(), basePath, zo, filtDir,   
                            filtFiles);  
    files[i].getPath(),  你这个根本就取不来我说得路径。只能取到\这个符号之前的,之后的取不到。
      

  3.   

        String sourcepath = sourceFile.getAbsolutePath(); 
    取得的值为空?