Storing and retriving file in MongoDB using Java & GridFs
<p>I would like to store a file in mongoDB and retrieve it from there to process it.
I have used the GRIDFS to store it</p>

<pre><code> Mongo mongo = new Mongo("localhost", 27017);
    DB db = mongo.getDB("HelloWorldDB");
    DBCollection collection = db.getCollection("Uploaded_Exclusion_files"); 
    GridFS gridfs = new GridFS(db, "downloads");
    GridFSInputFile gfsFile = gridfs.createFile(new File(fileName));
    gfsFile.setFilename("filename");
    gfsFile.save();

    BasicDBObject info = new BasicDBObject();
    info.put("name", "MongoDB");
    info.put("fileName", "filename");
    info.put("rawName", "fromJSON.csv");
    info.put("rawPath", "d:/fromJSON.csv");

    //
    // Let's store our document to MongoDB
    //
    collection.insert(info, WriteConcern.SAFE);


    DBCursor cursor= collection.find(info);
    while(cursor.hasNext()){
        System.out.println("Result "+cursor.next());
    }
        System.out.println("Done");     
</code></pre>

<p>but at the time of retrieving the file I don't l know what to  make it as a file and process it.</p>

<pre><code>            GridFSDBFile gfsFileOut = (GridFSDBFile) gridfs.findOne("filename");
            System.out.println(gfsFileOut.getInputStream());
            //##### WHAT TO DO TO GET THE FILE

    BufferedReader br = null;
    try {
        String sCurrentLine;
        br = new BufferedReader(new FileReader(&lt;#####I WANT TO PASS THE FILE TO PROCESS IT######&gt;));

        // ...          
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (br != null)
                br.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
</code></pre>

<p>I want to remove the file creation part in server and only wants to store in mongodb and retrieve it for processing it.</p>