lucene对数据库创建索引时报错:java.io.IOException: Cannot overwrite: D:\index\_3.fdt的解决办法

刚刚用lucene对数据库建立索引。当频繁的创建索引时总是报错:


java.io.IOException: Cannot overwrite: D:\index\_3.fdt

at org.apache.lucene.store.FSDirectory.initOutput(FSDirectory.java:372)
at org.apache.lucene.store.SimpleFSDirectory.createOutput(SimpleFSDirectory.java:58)
at org.apache.lucene.index.FieldsWriter.<init>(FieldsWriter.java:67)
at org.apache.lucene.index.StoredFieldsWriter.initFieldsWriter(StoredFieldsWriter.java:66)
at org.apache.lucene.index.StoredFieldsWriter.finishDocument(StoredFieldsWriter.java:144)
at org.apache.lucene.index.StoredFieldsWriter$PerDoc.finish(StoredFieldsWriter.java:189)
................................................



查了一下、终于解决了;

具体解决如下:在每次创建完索引之后都要关闭。也就是相当于conn.close()一样、所以加上这句话:

writer(IndexWriter的对象).close()就OK了、

你可能感兴趣的:(exception)