Java examples for Big Data:MongoDB
File read via mongodb GridFS
import com.mongodb.DB; import com.mongodb.MongoClient; import com.mongodb.gridfs.GridFS; import com.mongodb.gridfs.GridFSDBFile; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.sql.*; public class FileSearcher extends javax.swing.JFrame { private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed try {//www . j ava 2s . c o m MongoClient m = new MongoClient("localhost", 27017); DB db = m.getDB("mydb"); String attachmentName = "Attachment"; GridFS gfs = new GridFS(db, attachmentName); long timeBefore = System.nanoTime(); GridFSDBFile FileOutput = gfs.findOne(jTextField1.getText()); long timeAfter = System.nanoTime() - timeBefore; FileOutput.writeTo("E:\\" + FileOutput.getFilename()); jTextField2.setText("" + timeAfter); } catch (Exception e) { e.printStackTrace(); } // TODO add your handling code here: }//GEN-LAST:event_jButton1ActionPerformed }