java 往 mongo存儲時,由於bom格式,致使查詢不出來相關字符串java
大概是這麼存的。 讀取utf-8帶bom的txt,而後往mongo存,此時存的時候 ,就帶bom了。若是在查詢相關字符串,是查詢不到的。code
處理方式orm
private static final String allExportPath = "C://allExport.txt"; BufferedReader reader = null; //reader = new BufferedReader(new FileReader(file)); //使用BOMInputStream自動去除UTF-8中的BOM!!! reader = new BufferedReader(new InputStreamReader(new BOMInputStream(new FileInputStream(allExportPath)))); String name = null; //一次讀入一行(非空),直到讀入null爲文件結束 while ((name = reader.readLine()) != null) { if(MongoUtil.has("CompanyExportRecord","name",name)){ continue; } Map<String, Object> exportRecordMap = new HashMap<String, Object>(); exportRecordMap.put("name", name); exportRecordMap.put("time", new SimpleDateFormat(DateUtil.DATE_FORMAT_01).format(DateUtil.addDay(-1))); MongoUtil.saveDoc("CompanyExportRecord", exportRecordMap); }