file - Java InputStreamReader Can not read Special(Turkish) Characters -
below can see code;
final bufferedreader br = new bufferedreader( new inputstreamreader(new fileinputstream(f),"utf-8"));// tried "iso-8859-9" string strline; while ((strline = br.readline()) != null) { total += "\n" + strline; } br.close();
here below output.. should do?
insan�n sec�ld�g� combobox
the � or u+fffd character special character defined unicode "replacement character", character display when encounter character don't recognize, or byte data malformed , character cannot read.
the inputstreamreader
constructor using not allow specify behavior when there malformed data or when character not recognized. assumes want default behavior of using "replacement character" when there unrecognized character or when byte data malformed, may seeing.
if examine output , find turkish characters not there have been replaced "replacement character" u+fffd, can change behavior throw exception instead of using replacement character -- actual exception make easier detect when data in wrong character set.
to specify different behavior, use version of inputstreamreader
public inputstreamreader(inputstream in, charsetdecoder dec)
for charsetdecoder
, pass in
charset.newdecoder().onmalformedinput(codingerroraction.report) .onunmappablecharacter(codingerroraction.report)
where charset
character set of choice, e.g. standardcharsets.utf_8
that cause exception thrown rather replacement character inserted.
if still see replacement character , no exception thrown, it's clear problem in how viewing output.
Comments
Post a Comment