java 坐标处理_Java处理文件小例子--获取全国所有城市的坐标

packagecn.ycmedia.common.utils;importjava.io.BufferedReader;importjava.io.File;importjava.io.FileInputStream;importjava.io.InputStreamReader;importcom.alibaba.fastjson.JSONArray;importcom.alibaba.fastjson.JSONObject;importcom.qiniu.http.Response;public classReadTxt {static JSONObject jsxxsx = newJSONObject();public static voidreadTxtFile(String filePath){try{

String encoding="utf-8";

File file=newFile(filePath);

JSONObject json= newJSONObject();if(file.isFile() && file.exists()){ //判断文件是否存在

InputStreamReader read = newInputStreamReader(new FileInputStream(file),encoding);//考虑到编码格式

BufferedReader bufferedReader = newBufferedReader(read);

String lineTxt= null;

JSONObject js= null;while((lineTxt = bufferedReader.readLine()) != null){

js=JSONObject.parseObject(lineTxt);

JSONArray jsAr= js.getJSONArray("features");for (int i = 0; i < jsAr.size(); i++) {

JSONObject jsP=(JSONObject)jsAr.get(i);

JSONObject xx=jsP.getJSONObject("properties");

String city=xx.getString("name");

Double[] cp=xx.getObject("cp", Double[].class);

jsxxsx.put(city, cp);

}

}

read.close();

}else{

System.out.println("找不到指定的文件");

}

}catch(Exception e) {

System.out.println("读取文件内容出错");

e.printStackTrace();

}

}public static void main(String argv[]) throwsException{

showAllFiles(new File("D:\\test\\111"));

System.err.println(jsxxsx);

}public static void showAllFiles(File dir) throwsException {

File[] fs=dir.listFiles();for (int i = 0; i < fs.length; i++) {if(fs[i].isDirectory()) {try{

showAllFiles(fs[i]);

}catch(Exception e) {

}

}else{//打印返回的信息

readTxtFile(fs[i].getAbsolutePath());

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值