avatar

十六小站

欢迎来到我的个人主页! 期待与您分享我的经验与故事,一起探索技术的无穷可能!

  • 首页
  • NAS专题
  • 关于
Home 华为通讯录导出再导入到其他平台
文章

华为通讯录导出再导入到其他平台

Posted 2023-09-14 Updated 2024-10- 19
By 十六
4~5 min read

如题华为通讯录导出,再导入其他平台会出现名称错误的情况,这里我做了个小程序将导出的通讯录进行处理。程序如下:

import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DaoTest {

    public static void main(String[] args) {
        String sourcePath = "C:\\contacts.vcf";
        String targetPath = "C:\\contacts_out.vcf";

        try (BufferedReader reader = new BufferedReader(new FileReader(sourcePath))) {
            BufferedWriter fos = new BufferedWriter(new FileWriter(targetPath));
            String line;
            while ((line = reader.readLine()) != null) {

                String patternString = "(=[0-9A-Fa-f]{2})+";
                Pattern pattern = Pattern.compile(patternString);
                String replaceLine = null;

                if (line.startsWith("N;") || line.startsWith("ADR;") || line.startsWith("FN;") || line.startsWith("ORG;")){
                    Matcher matcher = pattern.matcher(line);
                    while (matcher.find()){
                        replaceLine = matcher.group();
                    }
                }

                if (replaceLine != null){
                    fos.write(line.replace(replaceLine, decodeName(replaceLine)) + "\n");
                } else {
                    fos.write(line + "\n");
                }
            }

            fos.flush();
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String decodeName(String hexEncodedString) throws UnsupportedEncodingException {

        String[] split = hexEncodedString.replaceFirst("=", "").split("=");
        byte[] bts = new byte[split.length];
        for (int i = 0; i < split.length; i++) {
            bts[i] = toByte(split[i]);
        }
        return new String(bts, "UTF-8");
    }

    public static byte toByte(String charObj){
        return (byte)Integer.parseInt(charObj, 16);
    }

}

Java程序直接执行就行,不懂的同学可以留言,后续我会做成在线转换工具。

License:  CC BY 4.0
Share

Further Reading

OLDER

Excel查找找出A列存在/不存在于B列的内容

NEWER

好站收藏

Recently Updated

  • Onlyoffice编译
  • K6+Playwright实现并发测试
  • 简单规则引擎
  • 在WEB中子线程可以访问Request上下文
  • onlyoffice配置

Trending Tags

Java Docker 前端 中间件 数据库 群晖 unraid

Contents

©2025 十六小站. 陕ICP备2023009742号-2