我有一个大的UTF-8输入,被分成了1KB大小的块。我需要使用接受String类型的方法来处理它。类似于:
for (File file: inputs) {
byte[] b = FileUtils.readFileToByteArray(file);
String str = new String(b, "UTF-8");
processor.process(str);
}
我的问题是我无法保证任何UTF-8字符不会在两个块之间拆分。运行我的代码的结果是一些行以“?”结尾,这破坏了我的输入。
解决这个问题的好方法是什么?
String
构造函数时跳过它。 - Alexander Pogrebnyak