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

发布于:2024-06-15 ⋅ 阅读:(175) ⋅ 点赞:(0)

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;
    }

网站公告

今日签到

点亮在社区的每一天
去签到