在Java中打印不可见字符的十六进制
我想在文件中打印出一些看不见的字符。如果我在Xcode中打开文件,它会将“^@”显示为不可见字符,而在TextMate中,如果我打开“显示不可见”选项,则会显示灰色菱形
我尝试了下面的代码,但打印出来的十六进制是“00”,我认为它代表null。如何打印文件中实际不可见字符的相应十六进制?提前谢谢
File file = new File("withInvisibles.txt");
Scanner sc = new Scanner (file);
while (sc.hasNextLine()) {
String words= sc.next();
System.out.println(String.format("%040x", new BigInteger(1, words.getBytes())));
}
sc.close();
# 1 楼答案
使用
(char)System.in.read()
代替扫描仪