当我尝试使用下面的
将一些文本内容设置到我们心爱的窗口的剪贴板时摘录,它可以正常工作,大约10-15MB。但超出该大小,它会抛出错误消息
最后显示的是。我们如何设置30多MB的utf文本到剪贴板?
代码:
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
File tmp = new File("c:\\web\\a.txt"); //This file's size > 38MB.
String s = readFileAsString(tmp);
cb.setContents(new StringSelection(s), null);
错误:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.lang.AbstractStringBuilder.<init>(AbstractStringBuilder.java:45)
at java.lang.StringBuffer.<init>(StringBuffer.java:91)
at sun.awt.datatransfer.DataTransferer.translateTransferable(DataTransferer.java:1001)
at sun.awt.windows.WDataTransferer.translateTransferable(WDataTransferer.java:163)
at sun.awt.windows.WClipboard.setContentsNative(WClipboard.java:73)
at sun.awt.datatransfer.SunClipboard.setContents(SunClipboard.java:93)
at com.webform.XMLReader.main(XMLReader.java:67)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)