[英]Gradle 2.3 + JUnit 4.11 = broken Charset
Under normal conditions in the correct bytes written to the file, but in conjunction Gradle 2.3 + JUnit 4.11 unexpected result. 在正常情况下,将正确的字节写入文件,但结合Gradle 2.3 + JUnit 4.11会出现意外结果。
import org.junit.Test;
import java.io.FileOutputStream;
import static org.junit.Assert.*;
public class TestUTF16Test
{
@Test
public void testWrite() throws Exception
{
try (FileOutputStream bin = new FileOutputStream("testUTF16junit.txt")) {
bin.write("Русский".getBytes("UTF-16LE"));
}
}
}
build.gradle 的build.gradle
apply plugin: 'java'
sourceCompatibility = 1.7
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
$ gradle.bat :clean :test $ gradle.bat:clean:test
:clean
:compileJavawarning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning
:processResources UP-TO-DATE
:classes
:compileTestJavawarning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning
:processTestResources UP-TO-DATE
:testClasses
:test
BUILD SUCCESSFUL
Total time: 4.999 secs
Result: 结果:
20 04 A0 00 21 04 53 04 21 04 03 04 21 04 03 04... 28 bytes
But it should be: 但是应该是:
20 04 43 04 41 04 41 04 3A 04 38 04 39 04 = 14 bytes
OS: Microsoft Windows 7 [Version 6.1.7601] 操作系统:Microsoft Windows 7 [Version 6.1.7601]
Gradle fix 摇篮修复
[ compileJava, compileTestJava ]*.options*.encoding = 'UTF-8'
2015, and javac can not recognize Unicode for BOM! 2015年,javac无法识别BOM的Unicode!
>javac.exe src\test\java\TestUTF16Test.java
src\test\java\TestUTF16Test.java:1: error: illegal character: '\u00bb'
я╗┐import org.junit.Test;
^
1 error
>javac.exe -version
javac 1.8.0_25
Now I understand why IDE doesn't add BOM... 现在我了解了为什么IDE不添加BOM表...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.