首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

依据文件名取文件【含相对路径和绝对路径处理】

2012-12-25 
根据文件名取文件【含相对路径和绝对路径处理】/*** 根据文件名取文件【含相对路径和绝对路径处理】* @param i

根据文件名取文件【含相对路径和绝对路径处理】
   /**
     * 根据文件名取文件【含相对路径和绝对路径处理】
     * @param inputfile
     * @return
     */
    public static File getFileByFileName(String inputfile){
        File inFile = null;
        String separator = System.getProperty("file.separator");
        if("\".equals(separator)){
            //windows版本
            if(inputfile.indexOf(":") > 0){
                inFile = new File(inputfile);
            }else{
                File file = new File("");
                String currFilePath = file.getAbsolutePath()+"\";
                inFile = new File(currFilePath+inputfile);
            }
        }else{
            //unix版本
            if(inputfile.startsWith("/")){
                inFile = new File(inputfile);
            }else{
                File file = new File("");
                String currFilePath = file.getAbsolutePath()+"/";
                inFile = new File(currFilePath+inputfile);
            }
        }
       
        System.out.print("\n currFilePath: " + inFile.getAbsolutePath());
        return inFile;
    }
   

热点排行