【问题标题】:How to find a file path in current java directory如何在当前java目录中查找文件路径
【发布时间】:2013-07-18 16:09:44
【问题描述】:

我有一个获取文件路径作为输入的函数。输入文件位于我的项目(etc/xsd/template.xsd)的一个文件夹中。如何设置这条路径?

这是我的功能:

JAXBUtilityTool 工具 = new JAXBUtilityTool("etc/xsd/template.xsd","src.com.classes");

找不到文件“etc/xsd/template.xsd”

System.getProperty("user.dir") 没有帮助,因为当我将其余路径添加到它时:

             System.getProperty("user.dir")+ "etc/xsd/template.xsd"

结果是 c:\eclipse\myworkingdirectory\project/etc/xsd/template.xsd

【问题讨论】:

    标签: filepath


    【解决方案1】:

    试试:

    String path = System.getProperty("user.dir");
    path = path.replaceAll("\\","/") + "/etc/xsd/template.xsd"
    

    来源:

    String.replaceAll single backslashes with double backslashes

    【讨论】:

    • 我不知道为什么!但它适用于 c:/eclipse/myworkingdirectory/project/etc/xsd/template.xsd 形式中的路径不使用 \ 所以如果我想用 / 替换 \ 我应该使用什么字符:string.replaceall("\" , ?????)
    猜你喜欢
    • 2012-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-20
    • 1970-01-01
    • 2011-03-26
    相关资源
    最近更新 更多