BufferedReader返回ISO-8859-15 String - 如何转换为UTF16 String? [英] BufferedReader returns ISO-8859-15 String - how to convert to UTF16 String?
问题描述
我有一个FTP客户端类,它返回InputStream指向该文件。我想用BufferedReader逐行读取文件。问题是,客户端以二进制模式返回文件,并且文件具有ISO-8859-15编码。
I have an FTP client class which returns InputStream pointing the file. I would like to read the file row by row with BufferedReader. The issue is, that the client returns the file in binary mode, and the file has ISO-8859-15 encoding.
推荐答案
如果文件/流/任何真正包含ISO-8859-15编码的文本,你只需要指定创建InputStreamReader时:
If the file/stream/whatever really contains ISO-8859-15 encoded text, you just need to specify that when you create the InputStreamReader:
BufferedReader br = new BufferedReader(
new InputStreamReader(ftp.getInputStream(), "ISO-8859-15"));
然后 readLine()
将创建有效的字符串在Java的本地编码(它是UTF-16,而不是UTF-8)。
Then readLine()
will create valid Strings in Java's native encoding (which is UTF-16, not UTF-8).
这篇关于BufferedReader返回ISO-8859-15 String - 如何转换为UTF16 String?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!