java.lang.RuntimeException: org.dom4j.DocumentException: E:\myeclipse\MyEclipse%2010\Workspaces\MyEclipse%2010\day09_user\WebRoot\WEB-INF\classes\users.xml (系统找不到指定的路径。) Nested exception: E:\myeclipse\MyEclipse%2010\Workspaces\MyEclipse%2010\day09_user\WebRoot\WEB-INF\classes\users.xml (系统找不到指定的路径。)
上面找到的路径与实际的路径(E:\myeclipse\MyEclipse 10\Workspaces\MyEclipse 10\day09_user\src\users.xml)不一致,怎么办?
代码是:
package cn.itcast.utils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
public class XmlUtils {
private static String filename="users.xml";
public static Document getDocument() throws DocumentException{
URL url=XmlUtils.class.getClassLoader().getResource(filename);
String path=url.getPath();
SAXReader reader = new SAXReader();
Document document = reader.read(new File(path));
return document;
}
------解决方案--------------------
实际放在哪里了?
你上边写的就是 classpath 资源路径
------解决方案--------------------
2个不一样的路径啊。
------解决方案--------------------
换个不包含特殊字符的路径试试!