0
I have a text file (txt) with 1000 lines, and I wanted to include them in the Clipboard. But from the examples I tested, only the last line is being copied to the Clipboard.
I looked for something like apend for Clipboard but not found. How can I do that?
Follow my attempt:
public class teste {
public static void main(String[] args) throws Throwable {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File("G:\\Arquivos"));
FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "text");
fileChooser.setFileFilter(filter);
fileChooser.showOpenDialog(null);
File selectedFile = fileChooser.getSelectedFile();
FileInputStream fs= new FileInputStream(selectedFile.getAbsolutePath());
BufferedReader br2 = new BufferedReader(new InputStreamReader(fs));
int bo = 0;
while(bo < 1){
try{
StringSelection selection = new StringSelection(br2.readLine());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
}catch(java.lang.IllegalStateException e){
bo = 1;
br2.close();
fs.close();
}
}
}
}
How do we know the packs of these classes there? ?
– user28595
It would be the case to accumulate everything in a string and make the setContents out of the loop.
– Bacco