我正在尝试从mongodb gridfs数据库中检索一个fie并将其存储在' data'我服务器的文件夹。但在执行此代码后,数据'文件夹仍然是空的。我无法理解为什么会这样。
String postno = request.getParameter("postno");
MongoClient mongo = new MongoClient();
DB db = mongo.getDB("blog");
HttpSession session = request.getSession();
String user = session.getAttribute("user").toString();
GridFS gfsmedia = new GridFS(db, user+"media");
List<GridFSDBFile> dbfiles = gfsmedia.find(new BasicDBObject("postno", Integer.parseInt(postno)));
//System.out.println(dbfiles);
for(GridFSDBFile dbfile : dbfiles)
{
String filename = dbfile.getFilename();
OutputStream out = dbfile.
System.out.println(filename);
File f = new File(getServletContext().getRealPath("") + File.separator + "data" + File.separator + filename);
dbfile.writeTo(f);
}