Copy to and Paste from Clipboard: A cross-platform solution in Java 复制并粘贴从剪贴板:一种跨平台的解决方案在Java
Have you ever felt the need for copying an output generated on command line to clipboard, or wanted to paste from clipboard to command line?您是否曾经感到需要复制一所产生的输出对命令行剪贴簿,或想从剪贴板粘贴到命令行?
The following java utilities (cross-platform) will help you do just that.下面的Java水电费(跨平台)将帮助您做到这一点。
Usage:用法:
=> To copy the output of a program to clipboard = >复制到输出的一个程序到剪贴板
echo Hello World | java ClipCopy回声的Hello World |手电clipcopy
dir | java ClipCopy迪尔|手电clipcopy
=> To paste the clipboard contents to a file = > ,以将剪贴板内容粘贴到一个文件
java ClipPaste > clip.txt Java的clippaste > clip.txt
This can also be used to remove the requirement to create temporary files in a complex batch/shell script.这也可以被用来移除的要求创建临时文件在一个复杂的批处理/ shell脚本。
To type clipboard contents directly from command line just type: java ClipCopy键入剪贴板内容直接从命令行只需键入: Java语言clipcopy
End with content with end character of your OS, Ctrl-Z for windows & Ctrl-D for Unix.结束与内容,与年底的性质您的操作系统,按Ctrl - Z的用于Windows &按Ctrl - D的UNIX的。
Download:下载:
ClipCopy.class clipcopy.class
ClipPaste.class clippaste.class
For line counters, ClipCopy is 4 lines of code and ClipPaste is 2 lines of code.线柜台, clipcopy是4行的代码和clippaste是2的代码行。 This doesn't take into account the import, class & main declarations and opening & closing braces.这并不顾及进口,阶级与主要的声明和开放与关闭牙套。
Let me know if you find this useful.让我知道,如果你觉得这是有益的。
Note: For non-Java users you might find it easier to download the注意:对于非Java用户,你会觉得更容易下载 jar file JAR文件 and run the modified commands as shown below:并运行该修改命令,如下所示:
Usage:用法:
=> To copy the output of a program to clipboard = >复制到输出的一个程序到剪贴板
echo Hello World | java -cp clip.jar ClipCopy回声的Hello World | Java的警务处处长clip.jar clipcopy
dir | java -cp clip.jar ClipCopy迪尔| Java的警务处处长clip.jar clipcopy
=> To paste the clipboard contents to a file = > ,以将剪贴板内容粘贴到一个文件
java -cp clip.jar ClipPaste > clip.txt Java的警务处处长clip.jar clippaste > clip.txt
This takes care of any classpath setting issue.这需要照顾的任何classpath下设置的问题。 You still need to have jre installed in your system.你还需要有JRE的安装在您的系统。
Limitation: Not tested with binary content.但不限于:尚未测试与二进制内容。 This is meant for text transfers only.这是指文字转让只。
Filed under提起下 Java Software Java软件 | |
| |
RSS 2.0 2.0 | |
Email this Article电子邮件此文章
You may also like to read您也可以想读 |




































March 15th, 2005 at 4:38 pm 2005年3月15日在下午4时38分
[...] ve it. [ … … ]维生素E 。 Remember to set Save as Type to HTML .记得设置保存类型为HTML 。 Open it in Internet Explorer and copy it to clipboard using Ctrl-A Ctrl-C afte [...]打开它在Internet Explorer和它复制到剪贴板使用Ctrl -一按Ctrl - C的后的[ … … ]
July 28th, 2005 at 1:24 pm 2005年7月28日在下午1时24分
hi there,喜有,
thank you.谢谢您。
I’ve previously managed something like this using perl我以前管理的一些像这样使用Perl
My perl script suffers though from not being able to copy multi-line output properly.我的Perl脚本患有虽然从没有能够复制多线输出。 I use the clipboard copy script using something like this我使用剪贴板复制脚本使用这样的
“cat blahblah.txt | xargs -0 clipcopy.pl” “猫blahblah.txt | xargs -0 clipcopy.pl ”
But… coming back to your program, on Windows XP,但…回到您的程序,在Windows XP上,
“dir | java -cp clip.jar ClipCopy” works just fine. “迪尔| Java的警务处处长clip.jar clipcopy ”工程只是罚款。
But when I try “cat cclcl.pl | xargs -0 java -cp clip.jar ClipCopy”, the program gets launched(which I observe by the delay) but I don’t see anything in the clipboard ??但是,当我尝试“猫cclcl.pl | xargs -0 Java的警务处处长clip.jar clipcopy ” ,该计划得到展开(我观察,由延迟) ,但我看不出有什么剪贴板吗?
BTW, I am using cygwin的BTW ,我用cygwin
Thank you,谢谢您,
BR,溴
~A 〜一
July 29th, 2005 at 9:57 am 2005年7月29日在上午09时57分
Try尝试
cat cclcl.pl | java -cp clip.jar ClipCopy猫cclcl.pl | Java的警务处处长clip.jar clipcopy
October 2nd, 2006 at 12:21 am 2006年10月2日在上午12时21分
I am having a problem with this application… it works well with “| java -cp clip.jar ClipCopy” piped from another command, but the problem is that it inserts a carriage return after the clipboard contents.我有一个问题,这与应用… …它运作良好,与“ | Java的警务处处长clip.jar clipcopy ”管道从另一个命令,但问题是,它插入一个回车后,将剪贴板内容。
For instance: “echo Hello World | java -cp clip.jar ClipCopy”例如: “回波的Hello World | Java的警务处处长clip.jar clipcopy ”
displays as: “Hello World显示为: “世界您好
” “
This is a problem for me as i need to be able to paste the string (Hello World) into another program and it wont let me.这是一个问题对我来说,正如我需要能够粘贴字符串(世界您好)到另一个程序,它wont让我。
Any thoughts on how to get around this?任何思想,就如何解决此问题?
Cheers,干杯,
Pete皮特
October 2nd, 2006 at 12:23 am 2006年10月2日在上午12时23分
Sorry, im using standard MS-DOS (WinXP)很抱歉,即时通讯使用标准的MS - DOS ( winxp )