[英]Transcoding with Gradle
我的 build.gradle 文件从项目模板生成 UNIX 和 Windows 启动器脚本。 模板是 UTF-8 编码的,生成的脚本也是 UTF-8。 It's not a problem on Linux where UTF-8 support is ubiquitous, but Windows has some issues displaying non Latin-1 characters in cmd.exe terminal window. After reading Using UTF-8 Encoding (CHCP 65001) in Command Prompt / Windows Powershell (Windows 10) I come to a conclusion that converting the generated UTF-8 script to cp1250 (in my case) would save me lots of trouble when displaying hungarian text. 但是我不知道如何将 UTF-8 文件转换为其他代码页(查看了副本,但没有找到指定 output 编码的方法。)
只需在构建文件中使用Apache Commons IO中的 FileUtils。
import org.apache.commons.io.FileUtils
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("commons-io:commons-io:2.8.0")
}
}
然后,在脚本的相关部分中,生成启动器脚本:
File f = file('/path/to/windows-launcher')
// Reading the content as UTF-8
String content = FileUtils.readFileToString(f, 'UTF-8')
// Rewriting the file as cp1250
FileUtils.write(f, content, "cp1250")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.