io - java.nio.charset.MalformedInputException: Input length = 1 -


i have (stripped html tags code example) function builds html table out of csv, runtime error everytime try run , don't know why. google says maybe encoding wrong have no idea how change that.

my csv encoded in ansi , contains characters ä, Ä, Ü, Ö have no control on encoding or if change in future.

the error occurs here:

caused by: java.io.uncheckedioexception: java.nio.charset.malformedinputexception: input length = 1 @ java.io.bufferedreader$1.hasnext(unknown source) @ java.util.iterator.foreachremaining(unknown source) @ java.util.spliterators$iteratorspliterator.foreachremaining(unknown source) @ java.util.stream.referencepipeline$head.foreach(unknown source) @ testgui.csv2html.start(csv2html.java:121) 

line 121 is

lines.foreach(line -> { 

sourcecode:

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(";");                 (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();             } {              }         });      } {         ps.close();     }  } 

you can try utilize correct encoding using files.lines(path path, charset charset) form of lines method (javadocs).

here's list of supported encodings (for oracle jvm anyhow). this post indicates "cp1252" windows ansi.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -