如何在Android中显示区域字符
我通过 Java 获取网站源代码并将其分配给一个字符串。但是当我看到该字符串的内容时,ara ?而不是 ç、ş、ı、ğ。希望你能帮助我。
I get a sites source code by Java and assign it to a string. But when i see content of that string there ara ? instead of ç,ş,İ,ğ. Hope you can help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DataInputStream.readLine
只能读取 latin1 编码的文本。您想要的字符不在 latin1 中,因此页面必须具有某种不同的编码,例如 UTF-8。假设页面以 UTF-8 编码,如果您将声明并初始化变量
in
的部分替换为以下内容,则可以读取它:如果您事先不知道页面编码,则可能会能够使用
URLConnection.getContentEncoding()
方法来查找。此方法返回在 HTTP 标头Content-Type
中声明的编码。如果内容类型没有编码,您只需猜测。DataInputStream.readLine
is capable of reading latin1-encoded text only. The characters you want are not in latin1 so the page must have some different encoding, such as UTF-8.Assuming the page is encoded in UTF-8 you can read it if you substitute the part where you declare and initialize the variable
in
with the following:If you don't know the page encoding beforehand you may be able to use the
URLConnection.getContentEncoding()
method to find out. This method returns the encoding declared i the HTTP headerContent-Type
. If the content type does not have the encoding you just have to guess.