1
我試圖以unamrshal一個XML文件中使用JAXB查找文件。出於某種原因,我不明白,我不能指向任何其他位置,然後在我的特定計算機上的完整路徑。在下面的代碼中,註釋行不起作用,但只有它上面的那一行。該文件確實存在(在兩個位置),並且註釋行對不同類有效。JAXB不能從相對路徑
JAXBContext jc = JAXBContext.newInstance(Monopoly.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
//unmarshaller.unmarshal(new File("resources/monopoly_config.xml"));
unmarshaller.unmarshal(new File("C:\\Users\\Lior\\Documents\\NetBeansProjects\\Monopoly curr\\MonopolyServer\\src\\BoardInfoResources\\monopoly_config.xml"));
ŧ他是答案。但是,只要添加它,你可以通過下面的方式來檢查你當前的工作目錄:System.out.println(System.getProperty(「user.dir」)); – Alvin 2011-05-25 17:52:11
謝謝你。不幸的是,這並沒有解決它。對不起,如果我以前不清楚 - 資源和BoardInfoResources都存在幷包含xml,但是,除非它是完整路徑,否則它將無法正常工作。 – Lior 2011-05-25 19:19:03
@Lior - 你是否按照Alvin的建議檢查你的工作目錄? – 2011-05-25 19:22:28