1.load 文件的时候
/**
* @param files
* @param col
* @throws XMLDBException
*/
private void addFiles(Collection col) throws XMLDBException {
File d = new File(dirPath);
if(!(d.canRead() && d.isDirectory()))
throw new RuntimeException("Cannot read directory: " + dirPath);
File[] files = d.listFiles();
for(int i = 0; i < files.length; i++) {
if(files[i].isFile()) {
System.out.println("Storing " + files[i].getName());
DBUtils.addXMLResource(col, files[i].getName(), files[i]);
}
}
System.out.println("All files stored.");
}
public static void addXMLResource(Collection col, String resourceId, File file) throws XMLDBException {
XMLResource res = (XMLResource)col.createResource(
resourceId, "XMLResource");
res.setContent(file);
col.storeResource(res);
}