从DB导出数据,生成UTF-16 Little Endian CSV文件


public SourceCsvInfo generateCsvFile(String userEmail, String productName, String version, String  baseName, String languageID,
                            List<SourceTargetDTO> sourceTargetDTOs) throws Exception {
    Language language =  languageRepository.getLanguageByID(languageID);
    String csvFileName =  productName + "_"  + version + "_" + baseName + "_" + language.getDecimalID() + ".csv";
    String[] folderArrInPath = {USER_DATA_FOLDER, userEmail, productName, version, EXPORT_CSV};
    String targetFolderRealPath = FilesUtil.createFolderPath(folderArrInPath);
    String targetFileRealPath = targetFolderRealPath + "\\" + csvFileName;
    File file = new File(targetFileRealPath);
    if (file.exists()) {
        file.delete();
    }
    FileOutputStream  fos = null;
    OutputStreamWriter  osw = null;
    BufferedWriter  bw = null;
    String[] csvFileColumnHeads = {"PSLCODE 235", "String ID", "9 1", language.getLanguagePrimaryId() + " " + language.getLanguageSubId(), "Comment"};
    String headLine =  String.join("\t", csvFileColumnHeads);
    try {
        fos = new FileOutputStream(file);
        osw = new OutputStreamWriter(fos, StandardCharsets.UTF_16LE);
        bw = new BufferedWriter(osw);
        bw.write("\uFEFF");
        bw.write(headLine);
        bw.newLine();
        for (SourceTargetDTO dto: sourceTargetDTOs) {
            String[] contentArray = {dto.getPslId(), dto.getPslStringId(), dto.getPslSourceString(), dto.getPslTargetString(), dto.getPslComment()};
            String contentLine = String.join("\t", contentArray);
            bw.write(contentLine);
            bw.newLine();
        }
        bw.flush();
        return new SourceCsvInfo(csvFileName, targetFileRealPath);
    } catch (Exception e) {
        throw e;
    } finally {
        if (bw != null) {
            bw.close();
        }
        if (osw != null) {
            osw.close();
        }
        if (fos != null) {
            fos.close();
        }
    }


 }


 
 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值