java.io.FileWriter class doesn’t use UTF-8 by default
来源:互联网 发布:考勤软件 编辑:程序博客网 时间:2024/06/06 05:32
Oddly enough the java.io.FileWriter class doesn’t use UTF-8 by default. I’m not exactly sure what 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");
Which ensures that you are using UTF-8.
I suppose that the motivation for this is that it means that simple use of FileWriter is compatible with applications that are not unicode aware and don’t support UTF-8. It probably makes sense at some level, but it just goes to show that you can’t assume anything.
- java.io.FileWriter class doesn’t use UTF-8 by default
- Caused by: java.sql.SQLException: Field 'id' doesn't have a default value
- Caused by: java.sql.SQLException: Field 'id' doesn't have a default value
- Caused by: java.sql.SQLException: Field 'id' doesn't have a default value
- Caused by: java.sql.SQLException: Field 'id' doesn't have a default value .
- Hibernate出现Caused by: java.sql.SQLException: Field 'id' doesn't have a default value原因
- cause by: java.sql,SQLException: Field 'pid' doesn't have a default value
- Caused by: java.sql.SQLException: Field 'id' doesn't have a default value
- Caused by: java.sql.SQLException: Field 'create_time' doesn't have a default value
- Hibernate中Caused by: java.sql.SQLException: Field 'address_id'doesn't have a default value
- Caused by: java.sql.SQLException: Field 'stu_id' doesn't have a default value
- java.lang.UnsupportedOperationException: UIL doesn't support scheme(protocol) by default
- Caused by: java.sql.SQLException: Field 'id' doesn't have a default value
- UIL doesn't support scheme(protocol) by default
- change MySQL's config file and let it use utf-8 by default
- Java Filewriter写文件UTF-8乱码
- Android报错解决 UIL doesn't support scheme(protocol) by default [file:/]. You should impleme
- 使用 ImageLoader报 UIL doesn't support scheme(protocol) by default 错误
- 七步理解深度学习
- 78. Subsets
- eclipse不编译
- CSS padding margin输入不同值个数的效果详解
- C++ 回调机制
- java.io.FileWriter class doesn’t use UTF-8 by default
- 51单片机入门之四:静态数码管
- JVM 内存初学 (堆(heap)、栈(stack)和方法区(method) ) http://www.open-open.com/lib/view/open1432200119489.html
- 委托
- [C++]类模板
- 字符串scanf,getchar,gets,printf,putchar输入输出小测试
- Maven 清晰介绍版
- 袁先生——安卓之路
- segment和polyhedron(obj)求交