Tag: 非法字符

如何检测非法的UTF-8字节序列以在java输入流中替换它们?

有问题的文件不在我的控制之下。 大多数字节序列都是有效的UTF-8,它不是ISO-8859-1(或其他编码)。 我想尽我所能提取尽可能多的信息。 该文件包含一些非法字节序列,应替换为替换字符。 这不是一件容易的事,它认为它需要一些关于UTF-8状态机的知识。 Oracle有一个包装器可以满足我的需求: UTF8ValidationFilter javadoc 是否有类似的东西(商业或免费软件)? 谢谢 -stephan 解: final BufferedInputStream in = new BufferedInputStream(istream); final CharsetDecoder charsetDecoder = StandardCharsets.UTF_8.newDecoder(); charsetDecoder.onMalformedInput(CodingErrorAction.REPLACE); charsetDecoder.onUnmappableCharacter(CodingErrorAction.REPLACE); final Reader inputReader = new InputStreamReader(in, charsetDecoder);

非法字符错误:’\ u200b’

我在面向对象编程类中为小行星游戏制作了一个小行星场,我收到了一个非法的字符错误:’\ u200b’。 问题似乎发生在第12行。(import java.awt.Point;和公共类Asteroid之间的界限扩展了PolyBlob) /* * University of Central Florida * COP3330 – Spring 2016 * Author: Aundray Ortiz */ package asteroidfield; import java.util.Random; import blobzx.PolyBlob; import blobzx.BlobUtils; import java.awt.Point; ​ public class Asteroid extends PolyBlob { private static final Random random = new Random(); public Asteroid(int a, int b, double c) { super(-100,-100,c); int […]