0

When I use Java to copy Japanese text to the clipboard, it can be retrieved again from Java code while the process is running but it does not successfully copy it to the system's global clipboard. It will just be empty so that nothing can be pasted. It does work with "regular" English text. How can this be fixed?

Here is the Japanese example text:

不要?
ガノンの形態によってステップを分けた方がいいかも

Here is the standard Java way of copying to the clipboard (I didn't really find another approach). For pasting you can use this code.

Usually Java-based copy/paste operations work better on Windows systems compared to *nix but this time even on Windows it's not copying it.

Using a command line command solution platform-dependently for Windows breaks horribly, the characters all get changed to question marks when copying to CMD.

Reading it in as a file (clip.exe < Japanese.txt) and copying it to the clipboard breaks too:

õ©ìÞªü´╝ƒ
Òé¼ÒâÄÒâ│Òü«Õ¢óµàïÒü½ÒéêÒüúÒüªÒé╣ÒâåÒââÒâùÒéÆÕêåÒüæÒüƒµû╣ÒüîÒüäÒüäÒüïÒéé

Is there really no solution to this?

BullyWiiPlaza
  • 17,329
  • 10
  • 113
  • 185
  • Perhaps, this article [Get Clipboard String Encoding (java)](https://stackoverflow.com/questions/17034956/get-clipboard-string-encoding-java) will be helpful. – kunif Jan 08 '18 at 12:09
  • @kunif: The Japanese text is detect as `UTF-8` and e.g. the English `Test` is detect as `ISO-8859-2`. I'm not sure how this helps now though. – BullyWiiPlaza Jan 08 '18 at 19:17
  • If the charset name could be determined, the simplest way would be an encoding conversion with String convertedstring = new String(clipboardstring.getBytes(), detectedcharsetname); – kunif Jan 08 '18 at 23:37
  • @kunif: But the problem is that the text is not copied to the global clipboard. The Java clipboard works fine at all times. I want to be able to use the text outside the Java application via paste. – BullyWiiPlaza Jan 08 '18 at 23:43
  • Please obtain a tool called clipboard monitor to see if data transfer is done and what the details of the data are. – kunif Jan 09 '18 at 00:58
  • Apply `chcp65001` _before_ `clip.exe < Japanese.txt`. – JosefZ Dec 26 '20 at 09:24

0 Answers0