unicode - how to convert ANSI to utf8 in java? -
this question has answer here:
i have text file ansi encoding, have convert utf8 encoding.
my text file stochastic programming area of mathematical programming studies how model decision problems under uncertainty. example, although decision might necessary @ given point in time, essential information might not available until later time.
you can explicit java.nio.charset.charset class (windows-1252 proper name ansi):
public static void main(string[] args) throws ioexception { path p = paths.get("file.txt"); bytebuffer bb = bytebuffer.wrap(files.readallbytes(p)); charbuffer cb = charset.forname("windows-1252").decode(bb); bb = charset.forname("utf-8").encode(cb); files.write(p, bb.array()); }
or in 1 line if prefer =)
files.write(paths.get("file.txt"), charset.forname("utf-8").encode(charset.forname("windows-1252").decode(bytebuffer.wrap(files.readallbytes(paths.get("file.txt"))))).array());
Comments
Post a Comment