Java : How to write content to file using utf 8
the default encoding is (possibly ISO-8859-1 or US-ASCII?) but it doesn’t seem to be UTF-8, which is odd given that java strings are supposed to be unicode. This causes a problem if you want to have non-ascii characters and you don’t realise what’s happening. This was a bug in SQLEditor and somebody accidentally typed an umlaut into one of the fields and the file wouldn’t reload. (Which was annoying).The correct thing to do seems to be to use the following:
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(path),"UTF-8");
My question is :
1. Not use FileOutputStream.Beacuse I must use File object (return by the third external api)
2. How to use File object to write utf8
When I use FileWriter,there are error encode for special char.(like ?) Java UTF-8 API filewriter --------------------编程问答-------------------- can you show the code of all your IO part? --------------------编程问答--------------------
--------------------编程问答-------------------- 好久不来.来看看呢.
PrintWriter w = new PrintWriter(file, "UTF-8");
w.println("你好");
补充:Java , Java SE