在网上的账户信息很多都忘了,一般是用Chrome记着然后自动登录。今天看了下发现还挺多的,于是想把密码都放到个人笔记里,就写了个转换的方法。记录下。
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 储存密码转为 markDown 表格形式 * @param path csv 文件路径 * @param isSkipIP 是否跳过IP网址 * @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){ sa[0] = su[0]; sa[1] = su[1]; sa[2] = su[2]; sa[3] = su[3] + "," + su[4]; sa[3] = sa[3].replaceAll(""",""); } else { sa = su; } if (i==1){ sb.append("|---|---|---|---| "); } 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(" "); } } } } log.info("开始输出..."); outputStream = new FileOutputStream(OUT_PATH); outputStream.write(sb.toString().getBytes(), 0, sb.toString().getBytes().length); log.info("成功输出到文件:{}", 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(); } } }