The chrome saved passwords into MarkDown form

Many account information online have forgotten, it is generally used Chrome remember and then automatically log on. Today saw the next discovery pretty much, so trying to put all personal notes in your password, you wrote a method to convert. record.

 

    private static final String IN_PATH = "D:\\out\\Chrome%20密码.csv";
    private static final String OUT_PATH = "D:\\out\\out.txt";

    public static void main(String[] args) throws IOException {
        String path = URLDecoder.decode(IN_PATH,"utf-8");
        read(path,true);
    }
    /**
     * Chrome store passwords into a tabular format markDown
     * @Param path CSV file path
     * @Param whether to skip IP URL isSkipIP
     * @return String
     */
    private static void read(String path, boolean isSkipIP) {
        BufferedReader bufferedReader = null;
        FileOutputStream outputStream = null;
        StringBuilder sb = new StringBuilder();
        try {
            bufferedReader = new BufferedReader(new FileReader(path));
            String str = null;
            List<String> strList = new ArrayList<>();
            while ((str = bufferedReader.readLine())!=null){
                strList.add(str);
            }
            for (int i = 0; i < strList.size(); i++) {
                String[] su = strList.get(i).split(",");
                String[] sa = new String[4];
                String pattern = "([0-9]+\\.)+[0-9]+";
                if (su.length > 4){
                    with [ 0] = su [0 ];
                    to [ 1] = the [1 ];
                    to [ 2] = the [2 ];
                    sa[3] = su[3] + "," + su[4];
                    sa[3] = sa[3].replaceAll("\"","");
                } else {
                    with = as;
                }
                if (i==1){
                    sb.append("|---|---|---|---|\r\n");
                }
                boolean is = false;
                if (isSkipIP){
                    is = Pattern.matches(pattern, sa[0]);
                }
                if (!is){
                    sb.append("|");
                    for (int j = 0; j < 4; j++) {
                        sb.append (sa [j]);
                        sb.append("|");
                        if (j==3){
                            sb.append("\r\n");
                        }
                    }
                }
            }
            log.info ( "start output ..." );
            outputStream = new FileOutputStream(OUT_PATH);
            outputStream.write(sb.toString().getBytes(), 0, sb.toString().getBytes().length);
            log.info ( "successfully output to a file: {}" , OUT_PATH);

        } catch (Exception e) {
            log.error("something is wrong, {}", e.getMessage());
            e.printStackTrace ();
        } finally {
            try {
                if (bufferedReader!=null){
                    bufferedReader.close();
                }
                if (outputStream!=null){
                    outputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace ();
            }
        }
    }

 

Guess you like

Origin www.cnblogs.com/meijsuger/p/12002330.html