【问题标题】:How to replace special character in java如何在java中替换特殊字符
【发布时间】:2016-04-26 15:00:45
【问题描述】:

I have a problem:

I copied more value (for example 23700 5000.2 0.000) from Excel file in a file .txt.

When I read in java this value stored in .txt file, and i copy this in another file .txt (with java), the result is the same:

23700 5000.2 0.000਍㈀㌀㜀㄀ ऀ㔀 㘀㜀⸀㜀ऀ ⸀㌀㌀㔀ഀ 23720 5067.7 0.670਍㈀㌀㜀㌀ ऀ㔀 㘀㜀⸀㜀ऀ㄀⸀  㔀ഀ 23740 5067.7 1.340਍㈀㌀㜀㔀 ऀ㔀 㘀㜀⸀㜀ऀ㄀⸀㘀㜀㔀ഀ 23760 5067.7 2.010਍㈀㌀㜀㜀 ऀ㔀 㘀㜀⸀㜀ऀ㈀⸀㌀㐀㔀ഀ 23780 5067.7 2.680਍㈀㌀㜀㤀 ऀ㔀 㘀㜀⸀㜀ऀ㌀⸀ ㄀㔀ഀ 23800 5067.7 3.351਍㈀㌀㠀㄀ ऀ㔀 㘀㜀⸀㜀ऀ㌀⸀㘀㠀㘀ഀ 23820 5067.7 4.021਍㈀㌀㠀㌀ ऀ㔀 㘀㜀⸀㜀ऀ㐀⸀㌀㔀㘀ഀ 23840 5067.7 4.691਍㈀㌀㠀㔀 ऀ㔀 㘀㜀⸀㜀ऀ㔀⸀ ㈀㘀ഀ 23860 5067.7 5.361਍㈀㌀㠀㜀 ऀ㔀 㘀㜀⸀㜀ऀ㔀⸀㘀㤀㘀ഀ 23880 5067.7 6.031਍㈀㌀㠀㤀 ऀ㔀 㘀㜀⸀㜀ऀ㘀⸀㌀㘀㘀ഀ 23900 5067.7 6.701਍㈀㌀㤀㄀ ऀ㠀㌀㘀㄀⸀㘀ऀ㜀⸀ ㌀㜀ഀ 23920 9577.0 7.372਍㈀㌀㤀㌀ ऀ㤀㔀㜀㜀⸀ ऀ㜀⸀㜀 㜀ഀ 23940 9577.0 8.042਍㈀㌀㤀㔀 ऀ㤀㔀㜀㜀⸀ ऀ㠀⸀㌀㜀㜀ഀ 23960 9577.0 8.712਍㈀㌀㤀㜀 ऀ㤀㔀㜀㜀⸀ ऀ㤀⸀ 㐀㜀ഀ 23980 9577.0 9.382਍㈀㌀㤀㤀 ऀ㤀㔀㜀㜀⸀ ऀ㤀⸀㜀㄀㜀ഀ

Can I eliminate this wrong character?

THX To all

【问题讨论】:

  • I suggest you read the Excel file as an excel file. e.g. use the POI API
  • There is no text but encoded text. Not knowing the character set and encoding of a ".txt" file is data loss. When you do know, you specify it in your file/stream/whatever reader (usually, it's an argument to the constructor.)

标签: java string character


【解决方案1】:

了解今天,文本文件并不全是 ascii。它们可以是 utf-8、latin-1、utf-16 等

问题可能是您在复制时打开的文本文件格式错误,或者写入的文本格式错误。要正确打开,请使用

InputStreamReader reader = new InputStreamReader(new FileInputStream(file),"utf-16");

将您的文件格式替换为 utf-16

对于写作,在FileOutputStream 上使用OutputStreamWriter

【讨论】:

  • 我在想有一天文本文件是 ASCII。在带有 RSX-11 操作系统的 Digital Equipment Corp PDP-11 上,我想他们可能是这样。 (我没有在 APL 中编程。)在我的 Corona Data Systems IBM 兼容 PC 上使用 MS-DOS 1.25,它们是 CP 437。╟画框字符当时真的很热╢(我们今天仍然在 Windows 中使用它们@987654324 @)
猜你喜欢
  • 2011-05-08
  • 1970-01-01
  • 1970-01-01
  • 2012-11-21
  • 2021-09-20
  • 1970-01-01
  • 1970-01-01
  • 2018-12-13
  • 2011-12-28
相关资源
最近更新 更多