【发布时间】:2013-12-04 23:06:03
【问题描述】:
- 我不想将整个文件加载到内存中
- 我不想对底层操作系统做任何假设。
我只剩下这个了:
echo it, "Checking file.. ${file.absolutePath}"
def fis = new FileInputStream(file)
def openingBytes = new byte[3]
try {
fis.read(openingBytes)
if (openingBytes.encodeHex() =~ /^efbbbf/) {
errors << file.path + " - File needs to be converted from UTF-8 BOM to UTF-8 without BOM"
}
} catch (Exception e) {
errors << "Encountered an error trying to check " + file.path + " for BOMs."
} finally {
fis.close()
}
但这看起来非常冗长且类似于 Java。 :-(
【问题讨论】:
标签: file utf-8 groovy byte byte-order-mark