从文件中读取特殊符号 [英] Read special symbols from file
问题描述
我正在尝试使用Java读取文件,并且该文件也包含特殊字符。
我正在尝试将文件内容写入另一个文件。
I am trying to read file using Java and the file also containing special characters also. I am trying to write the contents of file into another file.
读取特殊字符文件的解决方案是什么?
What is the solution to read special character files?
推荐答案
您需要找出文件使用的确切编码,然后在
InputStreamReader中指定
参数。
尽管通常将带有InputStreamReader的InputStream包装到Reader或BufferedReader中来读取字符数据
Nevertheless it is often best to reader character data by wrapping your InputStream with an InputStreamReader into Reader or BufferedReader
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(your file), "UTF-8"));
编辑评论:
FileReader
使用Java的平台默认编码,这取决于运行它的计算机的系统设置。
Edit For Comment:
FileReader
uses Java's platform default encoding, which depends on the system settings of the computer on which its running on.
不幸的是
FileReader
不允许设置编码。相反,您必须使用Above代码来获取文件的所需编码。
Unfortunately
FileReader
does not allow to set encoding. Instead, you have to use Above code to get the desire encoding for your file.
这篇关于从文件中读取特殊符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!