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();
}
}
}
从DB导出数据,生成UTF-16 Little Endian CSV文件
最新推荐文章于 2021-08-12 17:59:27 发布