简体   繁体   English

复制到剪贴板的JavaFX String从空字符'\\ u0000'开始被截断

[英]JavaFX String copied to the clipboard is truncated starting with null character '\u0000'

I have a String with null characters. 我有一个带空字符的字符串。 When I copy it to clipboard and paste to notepad, I receive only the beginning of the line, before null character. 当我将其复制到剪贴板并粘贴到记事本时,我只收到该行的开头,在空字符之前。 Is it a JavaFX bug? 它是JavaFX错误吗?

String data = "begginning\u0000ending";
ClipboardContent content = new ClipboardContent();
content.putString(data);
Clipboard.getSystemClipboard().setContent(content);
// Output will be "beginning"

That is likely a restriction of whatever clipboard system you're putting it in. A lot of those use C APIs under the hood and a C string can't contain a null character, because null is used as a terminator. 这可能是您要放入的任何剪贴板系统的限制。许多这样的用户在后台使用C API,并且C字符串不能包含null字符,因为将null用作终止符。

And indeed: Windows can't have null characters in the clipboard at all , and I suspect it's not alone in having this restriction. 的确如此: Windows剪贴板中根本不能包含空字符 ,而且我怀疑并非只有这种限制。

So in this case the result you got is the best that the JavaFX Clipboard API can hope to do. 因此,在这种情况下,您获得的结果是JavaFX Clipboard API希望达到的最佳效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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