Issue with spanish characters in java string

谁说我不能喝 提交于 2019-12-12 11:43:00

问题


I have issue with spanish characters in java string. I have a content in a file and when i try to transform it to java object using InputStreamReader, the output of some string is "cómo" which should be "cómo". This is happening other spanish like

á = á é = é í = í ó = ó ú = ú

and more..

Could you please help me to convert it appropriate output.

Thanks in advance


回答1:


Have you tried to specify the character encoding in the constructor of InputStreamReader, like so:

FileInputStream fis = new FileInputStream("file.txt");
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");



回答2:


Specify charset on your InputStreamReader - http://download.oracle.com/javase/1.5.0/docs/api/java/io/InputStreamReader.html#InputStreamReader(java.io.InputStream, java.lang.String)



来源:https://stackoverflow.com/questions/4857102/issue-with-spanish-characters-in-java-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!