Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 加载不同目录中的文件_Java - Fatal编程技术网

Java 加载不同目录中的文件

Java 加载不同目录中的文件,java,Java,我想加载位于不同目录中的xml配置文件 文件的位置为: <location_dir>/jar_file.jar <location_dir>/xml_file.xml 我想问的是,这个例子对每个操作系统都通用吗?只要你使用File.separator它就是通用的例子。我如何改进代码?不能说,不知道解组方法是什么 public class SeparatorTest { private static SettingsDataObject settingsData;

我想加载位于不同目录中的xml配置文件

文件的位置为:

<location_dir>/jar_file.jar
<location_dir>/xml_file.xml

我想问的是,这个例子对每个操作系统都通用吗?

只要你使用
File.separator
它就是通用的例子。我如何改进代码?不能说,不知道解组方法是什么
public class SeparatorTest
{
    private static SettingsDataObject settingsData;

    public void loadXMLFile() throws JAXBException
    {

        try
        {

            // File location by default     ../conf/xmlfile.xml
            settingsData = unmarshal(".." + File.separator + "conf" + File.separator + "xmlfile.xml");

        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
    }

}