private void parsexmlfile(){ 属性property = new Properties();
try {
InputStream stream = new FileInputStream("abc.properties");
property.load(stream);
} catch (Exception e) {
e.printStackTrace();
}
try {
// final File folder = new File("/home/you/Desktop");
final File file = new File(property.getProperty("db.filenew"));
File files[] = file.listFiles();
for (File fileone : files) {
if (fileone.isFile()
&& fileone.getAbsolutePath().endsWith(".xml"))
;
System.out.println(fileone.getCanonicalPath());
DocumentBuilderFactory builderFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder db = builderFactory.newDocumentBuilder();
dom = db.parse(file);
parsedocument();
if (file.renameTo(new File(property.getProperty("db.fileold")
+ file.getName()))) {
System.out.println("moving done...");
} else
System.out.println("not moving...");
}
但是我得到了像
这样的例外oracle.xml.parser.v2.XMLParseException; systemId: file:/D:/Accessing/sync/Stores/; lineNumber: 1; columnNumber: 1; Start of root element expected.
at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:320)
at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:329)
at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:291)
at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:207)
at oracle.xml.jaxp.JXDocumentBuilder.parse(JXDocumentBuilder.java:155)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at com.ssg.read.ReadXmlFile.parsexmlfile(ReadXmlFile.java:101)
at com.ssg.read.ReadXmlFile.run_Store(ReadXmlFile.java:71)
at com.ssg.read.ReadXmlFile.main(ReadXmlFile.java:440)
我怎么能解决这个问题?请帮帮我......
答案 0 :(得分:1)
你有一个空(null)if条件。
if (fileone.isFile()
&& fileone.getAbsolutePath().endsWith(".xml"))
;
这意味着,您只需评估属性db.filenew
指向的文件夹中的每个文件和/或目录。所以你可能需要一个支架并从末端删除分号。
if (fileone.isFile()
&& fileone.getAbsolutePath().endsWith(".xml")) {
//then parse the xml file
}