当前位置:编程学习 > JAVA >>

JAVA彻底解决获取空格路径问题

Java代码 
ReadProperties read = new ReadProperties("db"); 
        double currentVersion = Double.valueOf(read.readProperties("Version")); 
        if (version <= currentVersion) { 
            String path = Thread.currentThread().getContextClassLoader() 
                    .getResource("").toString();//获取更目录地址 
            path = path.substring(path.indexOf("/") + 1, path.length()) + "pda"; 
            try { 
                path = URLDecoder.decode(path, "utf-8"); 
            } catch (UnsupportedEncodingException e) { 
                e.printStackTrace(); 
            }// 关键啊 !主要转换文件地址,避免空格问题 
            System.out.println(path); 


Java代码 
D:/D/Java/Apache/apache-tomcat-7.0.20 - Copy/webapps/xhsd/WEB-INF/classes/pda 

补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,