算法:读取redis中指令查询的键

1,redis查询的代码:

  • 只读取双引号奇数行的数
 34575)  "7193139"
 34576)  "0"
 34577)  "7078990"
 34578)  "0"
 34579)  "7296242"
 34580)  "0"
 34581)  "1650126"
 34582)  "0"
 34583)  "7216950"
 34584)  "0"
 34585)  "1320150"
 34586)  "0"
 34587)  "4289607"
 34588)  "0"
 34589)  "7194919"
 34590)  "0"
 34591)  "7326747"
 34592)  "0"
 34593)  "7181311"
 34594)  "0"
 34595)  "2241942"
 34596)  "0"
 34597)  "7320020"
 34598)  "0"
 34599)  "7287031"
 34600)  "0"
 34601)  "7275622"
 34602)  "0"
 34603)  "7121939"
 34604)  "0"
 34605)  "7078525"
 34606)  "0"
 34607)  "7057849"
 34608)  "0"
 34609)  "5111838"
 34610)  "0"
 34611)  "7316611"
 34612)  "0"
 34613)  "7257737"
 34614)  "0"
 34615)  "7154046"
 34616)  "0"
 34617)  "619524"
 34618)  "0"
 34619)  "7298400"
 34620)  "0"
 34621)  "7093178"
 34622)  "0"
 34623)  "3276645"
 34624)  "0"
 34625)  "7082073"
 34626)  "0"
 34627)  "7137103"
 34628)  "0"
 34629)  "7110467"
 34630)  "0"
 34631)  "7324956"
 34632)  "0"
 34633)  "7206415"
 34634)  "0"
 34635)  "7076793"
 34636)  "0"
 34637)  "7135559"
 34638)  "0"
 34639)  "7247672"
 34640)  "0"
 34641)  "7133994"
 34642)  "0"
 34643)  "7117134"
 34644)  "0"
 34645)  "7195882"
 34646)  "0"
 34647)  "7101595"
 34648)  "0"
 34649)  "7329487"
 34650)  "0"
 34651)  "7276077"
 34652)  "0"
 34653)  "7223919"
 34654)  "0"
 34655)  "1075708"
 34656)  "0"
 34657)  "7203881"
 34658)  "0"
 34659)  "7056950"
 34660)  "0"
 34661)  "7291432"
 34662)  "0"
 34663)  "7081932"
 34664)  "0"
 34665)  "7322325"
 34666)  "0"
 34667)  "7268772"
 34668)  "0"
 34669)  "7276632"
 34670)  "0"
 34671)  "7216135"
 34672)  "0"
 34673)  "372976"
 34674)  "0"
 34675)  "7290238"
 34676)  "0"

2,代码实现:

    /**
     * 读取文件并截取字符串
     * @throws FileNotFoundException
     */
    @Test
    public void test003() throws FileNotFoundException {
        //
        File file = new File("D:\\1,install\\DesktopFiles\\001.txt");
        String s = "D:\\1,install\\DesktopFiles\\001.txt";
        int[] ints = toArrayByFileReader1(s);
        for (int i = 0; i < ints.length; i++) {
            System.out.println(ints[i]);
        }
    }

    /**
     *  按行读取,读取双引号里面的数据
     * @param name
     * @return
     */
    public static int[] toArrayByFileReader1(String name) {

        // 使用ArrayList来存储每行读取到的字符串
        ArrayList<String> arrayList = new ArrayList<String>();
        try {
            FileReader fr = new FileReader(name);
            BufferedReader bf = new BufferedReader(fr);
            String str;
            int sum = 0;
            // 按行读取字符串
            while ((str = bf.readLine()) != null) {
                if(sum%2 == 0){
                    int i = str.lastIndexOf('"');
                    int i1 = str.indexOf('"');
                    String substring = str.substring(i1+1, i);
                    arrayList.add(substring);
                }
                sum++;
            }
            bf.close();
            fr.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 对ArrayList中存储的字符串进行处理
        int length = arrayList.size();
        int[] array = new int[length];
        for (int i = 0; i < length; i++) {
            String s = arrayList.get(i);
            array[i] = Integer.parseInt(s);
        }
        // 返回数组
        return array;
    }
  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

java我跟你拼了

您的鼓励是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值