3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by javed123
0

following example will take whatever text in your clipboard into string and will print on console

import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

public class ClipboardCopyMaker {

	public static void main(String[] args) {

		copyToSystemClipboard();
	}

	public static void copyToSystemClipboard() {
		try {
			String dataFlavor = Toolkit.getDefaultToolkit()
					.getSystemClipboard().getData(DataFlavor.stringFlavor)
					.toString();
			System.out.println(dataFlavor);
		} catch (HeadlessException e) {
			e.printStackTrace();
		} catch (UnsupportedFlavorException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Edited by javed123: n/a

0

Interesting, Javed123.
This appears to be version of the code in the link I posted earlier, but with less checking, and totally misleading names ("copyToSystemClipboard" copies from the clipboard, "dataFlavor" holds the data String, not the DataFlavor).
Not sure what you are trying to contribute here...

0

Interesting, Javed123.
This appears to be version of the code in the link I posted earlier, but with less checking, and totally misleading names ("copyToSystemClipboard" copies from the clipboard, "dataFlavor" holds the data String, not the DataFlavor).
Not sure what you are trying to contribute here...

@JamesCherrill

Yes, there are misleading names in sample code i had posted and this happened because I was trying both programs at same time
1. copying from system clipboard
2. copying to system clipboard

I think I am giving here what thread poster is looking for.

:-O:-O

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.