2013-10-11 19 views
0

如何使用Java應用程序將系統文件添加爲使用Couchdb4J庫的Couchdb數據庫的附件?如何使用Couchdb4j庫向CouchDB添加附件

我試着修改下面的示例代碼,但有一個未解決的錯誤。有人知道我的錯誤在哪裏以及如何解決?提前致謝。

import java.io.File; 
import java.io.FileInputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.util.HashMap; 
import java.util.Map; 

import com.fourspaces.couchdb.CouchResponse; 
import com.fourspaces.couchdb.Database; 
import com.fourspaces.couchdb.Document; 
import com.fourspaces.couchdb.Session; 

public class FileScanner { 

Session priceListDocsSession = new Session("localhost",5984); 
    Database db = priceListDocsSession.getDatabase("filesdb"); 

    public static void main(String[] args) { 
    FileScanner fs = new FileScanner(); 

fs.processDir(new File("C:\\CouchDB")); 
} 

void processDir(File f) { 
if (f.isFile()) { 
    Map<String, Object> doc = new HashMap<String, Object>(); 
    doc.put("name", f.getName()); 
    doc.put("path", f.getAbsolutePath()); 
    doc.put("size", f.length()); 


    db.saveDocument(doc); 
    InputStream is = new FileInputStream(f); 
    String att=db.putAttachment(doc.getId(),doc.getRev(),f,is); 
    } 
else { 
    File[] fileList = f.listFiles(); 
    if (fileList == null) return; 
    for (int i = 0; i < fileList.length; i++) { 
    try { 
     processDir(fileList[i]); 
    } catch (Exception e) { 
     System.out.println(e); 
     } 

     } 
    } 
    } 
} 

的錯誤出現在db.saveDocument(doc);

String att=db.putAttachment(doc.getId(),doc.getRev(),f,is);.getId()getRev()未定義類型映射

回答

0

我加入了一些jcouchdb的管理,以固定的問題依賴於類路徑。