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); }