如何解决FileOutputStream设置编码,并将字节写入文件
我有一个csv文件,我使用utf-8编码将其保存,如下所示: reference
FileOutputStream fileOut =fileOut = new FileOutputStream(file,true);
/*utf-8 setting*/
fileOut.write(0xef);
fileOut.write(0xbb);
fileOut.write(0xbf);
/*append another string*/
PrintWriter printWriter = new PrintWriter(fileOut);
printWriter.write(...);
我将字符串写入文件,并且可以使用UTF-8
编码正常工作。
我的问题是:
- 有人知道这是什么字节吗?
- 如何将其更改为另一种编码,例如
cp1256
? - 是提供所有编码的列表吗?
更新: 假设我保存了在分页中创建的巨大字符串数据,并且无法一次存储此大小的数据。
谢谢
解决方法
为什么不使用Apache Commons中的FileUtils? 这将使您的生活更加轻松。 ;-)
而且,如果您想隐藏内容,请在这里查看:Encoding conversion in java
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
</dependency>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。