我有这个(剥离代码示例的HTML标签)函数,该函数从CSV中构建HTML表格,但每次尝试运行时都会收到运行时错误它和我不知道为什么。谷歌说,也许编码的东西是错的,但我不知道如何改变它。java.nio.charset.MalformedInputException:输入长度= 1
我的CSV以ANSI编码,包含像ä,Ä,Ü,Ö这样的字符,但我无法控制编码或将来是否会更改。
这里出现的错误:
Caused by: java.io.UncheckedIOException: java.nio.charset.MalformedInputException: Input length = 1
at java.io.BufferedReader$1.hasNext(Unknown Source)
at java.util.Iterator.forEachRemaining(Unknown Source)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Unknown Source)
at java.util.stream.ReferencePipeline$Head.forEach(Unknown Source)
at testgui.Csv2Html.start(Csv2Html.java:121)
121线是
lines.forEach(line -> {
源代码:
protected void start() throws Exception {
Path path = Paths.get(inputFile);
FileOutputStream fos = new FileOutputStream(outputFile, true);
PrintStream ps = new PrintStream(fos);
boolean withTableHeader = (inputFile.length() != 0);
try {
Stream<String> lines = Files.lines(path);
lines.forEach(line -> {
try {
String[] columns = line.split(";");
for (int i=0; i<columns.length; i++) {
columns[i] = escapeHTMLChars(columns[i]);
}
if (withTableHeader == true && firstLine == true) {
tableHeader(ps, columns);
firstLine = false;
} else {
tableRow(ps, columns);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
});
} finally {
ps.close();
}
}
对于当前(和未来)参考:如果您还告诉我们发生异常的代码行,这非常有用。 –
*我每次尝试运行时都会收到运行时错误*哪个错误?请分享。 –
对不起,添加了例外的相关部分和行号。 – Vega