简体   繁体   中英

How to replace special character in java

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

Understand that today, text files are not all ascii. They can be utf-8, latin-1, utf-16, etc

The problem is likely that in your copying you are either opening the text file with the wrong text format, or writing it with the wrong text format. To open correctly, use

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

substitute your file format for utf-16

For writing, use an OutputStreamWriter on a FileOutputStream

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM