对指定文件的某部分数据提取

  在论文的实验中要实现在数据集中提取目标经纬度,通过识别指定标识符方法提取经纬度。本人水平有限,写的代码巨麻烦,时间复杂度为O(n3)。希望得到指点。

此为数据集内容:

0    2010-10-09T05:45:25Z    39.891077    -105.068532    6f3a2db56d4fa788f72def616f79b7a4
0    2010-10-08T03:33:37Z    39.758974    -105.010853    11da318f0ea3c4a8f447500c543cb694
0    2010-10-08T00:38:51Z    39.747228    -104.994783    ce162b33ed2c7b98e2aced2799aa5b20
0    2010-10-07T23:38:04Z    39.752508    -104.996637    424eb3dd143292f9e013efa00486c907
3    2010-07-04T21:53:19Z    37.761114    -122.434559    0bfba36f93e7d7b1af9a47be0462c1c1
3    2010-07-04T06:57:44Z    37.740104    -122.438231    e0d90ce08dd211dd9d9e003048c0801e
2016    2009-05-01T07:25:28Z    34.715235    136.970332    dcf9ca6c361811de9186003048c0801e
2016    2009-05-01T04:56:03Z    34.709595    136.968872    bc68a152360311de91e6003048c10834
2016    2009-05-01T03:33:55Z    35.041763    137.044357    6d30e2c635f811de8ba1003048c0801e
2016    2009-04-30T11:36:19Z    35.590454    139.596802    4740990e357011dea269003048c0801e

此为做完之后得到的内容:

39.891077    -105.068532
39.758974    -105.010853
39.747228    -104.994783
39.752508    -104.996637
37.761114    -122.434559
37.740104    -122.438231
34.715235    136.970332
34.709595    136.968872
35.041763    137.044357
35.590454    139.596802

代码如下:

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;



public class RWtxt {

    public static void main(String[] args) 
    {
        try 
            {
                int i = 0;
                int k = 1;
                FileReader fis = new FileReader("data.txt");
                FileWriter fos = new FileWriter("data_2.txt");
                char[] input = new char[1];
                int hasRead = 0;
                f1:while((hasRead = fis.read(input)) > 0)
                {
                    if(input[0] == 90)
                    {
                        f2:while((hasRead = fis.read(input)) > 0)
                        {
                            if(input[0] == 9)
                            {
                                i++;
                            }
                            if(input[0] != 9)
                            {
                                fos.write(input);
                                System.out.print(new String(input , 0 , hasRead));
                            }
                            if(i == 2)
                            {
                                if(k == 1)
                                {
                                    fos.write(9);
                                    System.out.print("\t");
                                    k--;
                                }
                            }
                            if(i == 3)
                            {
                                fos.write("\r\n");
                                System.out.print("\n");
                                i = 0;
                                k = 1;
                                break f2;
                            }
                        }
                    }
                }
                fis.close();
                fos.close();
            } catch (FileNotFoundException e) {
                    e.printStackTrace();
            } catch (IOException e) {
                    e.printStackTrace();
            }
        }
    }

 

转载于:https://www.cnblogs.com/Uncle-Sam/p/5066911.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值