欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

如何在Java中处理LNK文件:通过文件流进行解析指南

最编程 2024-02-22 19:26:03
...
public static void main(String[] args) throws IOException {
        String jsonpath="E:\\河南省乡镇点\\12.txt";
        ReadGeojson.ReadGeojsonFile(jsonpath);
    }
    public static void ReadGeojsonFile(String jsonpath) throws IOException {
        //读取txt文件流
        File file=new File(jsonpath);
        FileInputStream fileInputStream = new FileInputStream(file);
        InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream,"UTF-8");
        BufferedReader bufReader = new BufferedReader(inputStreamReader);
        try {
            String  line="";
            //读取每行内容
            StringBuffer sb=new StringBuffer();
            while ((line=bufReader.readLine())!=null){
                sb.append(line);
            }
            //去除空格
            String sbreplace = sb.toString().replace(" ", "");
            System.out.println(sbreplace);
            //转换成为JSONObject对象
            JSONObject jsonObj =new JSONObject(sbreplace);
            System.out.println(jsonObj.get("dataType"));
            //第二层
            Object attributes = jsonObj.get("attributes");
            System.out.println(attributes);
            JSONObject attributesObj =new JSONObject(attributes.toString());
            System.out.println(attributesObj.get("userId"));
            //数组形式
            JSONArray geometry =(JSONArray) jsonObj.get("geometry");
            System.out.println(geometry.get(0));
            System.out.println(geometry.toString());

        } catch (IOException  e) {
            e.printStackTrace();
        }

        bufReader.close();
    }
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.

推荐阅读