c java utf 8,用BOM编译(javac)UTF8编码的Java源代码

Hello and thank you for reading my post.

My problem is the following: I want to compile a Java source file with "javac" with this file being UTF-8 encoded with a BOM (the OS is WinXP).

Below is what I do:

1) Create a file with "Notepad" and choose the UTF-8 encoding

dos> notepad Test.java

"File -> Save as..."

File name : Test.java

Save as type: All Files

Encoding : UTF-8

Save

2) Create a Java class in that file and saved the file like in 1)

public class Test

{

public static void main(String [] args)

{

System.out.println("This is a test.");

}

}

3) Visualize the hexadecimal version of the file (first line)

dos> xxd Test.java | head -1

0000000: efbb bf70 7562 6c69 6320 636c 6173 7320 ...public class

Note:

ef bb bf is the UTF-8 encoded BOM (the UTF-16 encoded BOM being FE FF).

4) Try to compile this code with "javac"

dos> javac -encoding utf8 Test.java

Test.java:1: illegal character: \65279

?public class Test

^

1 error

Note: 65279 is the decimal version of the BOM.

My question is the following: how can I make this compiling work with:

keeping it UTF-8 encoded

and keeping the BOM?

Thank you for helping and best regards.

Léa

解决方案

Trim the BOM and then use javac -encoding utf8 x.java

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值