使用到了org.json包
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.roiland.mongodb.bean.EcuDictBean;
public class importMongoDB {
static String path="C:\\Users\\Desktop\\ed.txt";
static String jsonPath="C:\\Users\\Desktop\\edjson.txt";
public static List parseString(String src){
List list = new LinkedList();
String[] str = src.split("\r\n");
for(int i =1;i<str.length;i++){
String[] str1 = str[i].split(",");
}
return list;
}
/**
*
*/
public static void getJsonFile(){
StringBuffer stringBuffer = new StringBuffer();
List list = new LinkedList();
String line = null ;
try {
BufferedReader br = new BufferedReader(new FileReader(new File(jsonPath)));
while( (line = br.readLine())!= null ){
stringBuffer.append(line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
String[] str = stringBuffer.toString().split("}},");
System.out.println(str.length);
for(String s:str){
JSONObject jsonObject = new JSONObject(s+"}},");
JSONArray x = jsonObject.getJSONArray("dv") ;
String ei = (String) jsonObject.get("ei");
String on = (String) jsonObject.get("on");
JSONObject tsJson = (JSONObject) jsonObject.get("ts");
//String ts= String.valueOf(tsJson.getLong("$date));
long l = tsJson.getLong("$date");
EcuDictBean ed = new EcuDictBean();
List<String> dvlist = new ArrayList<String>();
if(x.length()>0){
for(int i=0;i<x.length();i++){
dvlist.add((String) x.get(i));
}
}
ed.setDv(dvlist);
ed.setEi(ei.toString());
ed.setOn(on.toString());
Date d = new Date(l);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
sdf.format(d);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
public static String getFile(){
StringBuilder sb=new StringBuilder();
try {
File inFile = new File(path);
FileInputStream fi = new FileInputStream(inFile);
byte[] b = new byte[fi.available()];
fi.read(b);
for(byte c : b){
char temp = (char)c;
sb.append(temp);
}
fi.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
/**
* @param args
*/
public static void main(String[] args) {
getJsonFile();
//String str =getFile();
}
}
分享到:
相关推荐
Java 解析xml 存入mongodb 返回org.json json包
主要介绍了MongoDB导出查询结果到文件例子,本文直接给出示例代码,简洁易懂,需要的朋友可以参考下
1.java连接mongo数据库查询统计信息导出为excel表格 2.所有连接参数都可以动态输入,参数包括:ip、端口、数据库名称、集合名称、查询参数(公众号,写在指定文件中),导出表格存放位置
mongodb创建库以及基本使用脚本说明.
MongoDB构建分布式文件存储的数据库MongoDB构建分布式文件存储的
MongoDB数据库配置文件配置项,详细讲述MongoDB数据库配置文件中常需要的各类配置项详细讲述MongoDB数据库配置文件中常需要的各类配置项
该模块不再被维护。 请参阅: :
mongodb的配置文件标准化介绍与最常用的三种启动方式
MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。导入导出很管用啊
MongoDB练习文件
MongoDB之conf配置文件详解
利用MongoDB与Jackson JSON框架结合实现快速开发应用接口的例子,详情参见文章:http://blog.csdn.net/chaijunkun/article/details/7263804。
本文介绍了MongoDB的内部构造,对于大多数的MongoDB的用户来说,MongoDB就像是一个大黑盒,你有必要了解它的内部构造
mongodb4.2配置文件
.net 链接mongodb的dll文件
MongoDB数据库文件-名言警句集合,导入即可使用 MongoDB数据库文件-名言警句集合,导入即可使用 MongoDB数据库文件-名言警句集合,导入即可使用 MongoDB数据库文件-名言警句集合,导入即可使用 MongoDB数据库文件-...
深入解析MongoDB聚合与索引:提升数据库效能的关键策略
此文件中包含了目前最新的MongoDB的安装文件以及补丁文件。还提供了一个MongoDB的可视化工具。如有需要请下载
ExpressMongoPortfolio 继续ReactNative,但用Express和MongoDB替换json-server
MongoDB的配置文件信息,加载mongodb的属性配置文件,配置mongodb客户端,配置工厂 引用mongodb客户端