请非常小心地避免使用平台默认编码的 API 调用(首先是:FileReader/Writer)除非您在没有显式声明编码的情况下处理用户提供的数据
如果文件格式/网络协议确实有显式编码声明,请确保正确使用它
Avoid converting between bytes and strings needlessly
Be aware that werever you convert between bytes and strings, there is an encoding involved, implicitly or explicitly
Be very careful to avoid the API calls that use the platform default encoding (first and foremost: FileReader/Writer) unless you are handling user-supplied data without an explicitly declared encoding
If the file format / network protocol does have an explicit encoding declaration, make sure you use it correctly
发布评论
评论(2)
我的建议是如果可能的话使用
java.io.Reader
/java.io.Writer
,并在使用InputStreamReader
/ <时设置字符代码>OutputStreamWriter。My advice is to use
java.io.Reader
/java.io.Writer
if possible, and set the character when you useInputStreamReader
/OutputStreamWriter
.