I am trying to copy a text file using scanner to the clipboard. Can someone tell me what my clipboard.setContents method should look like?
This is what I have now:
import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.io.File; import java.util.Scanner; public class Main { public static void main(String[] args) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); File file = new File ("c:\\Temp\\testdata.txt"); try{ Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { String line = scanner.nextLine(); System.out.println(line); } clipboard.setContents(new StringSelection("string"), null); //right now this just copies "string" to the clipboard. I need it to copy the scanned in file to the clipboard. } catch (Exception e) {} } }