Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Copying file from Java to System clipboard help

 
S Saunders
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to write some code that will allow the user to select a file in a java application and then be copied to the system clipboard for them to paste into a folder in the Windows Explorer.
Currently when I try this, the path of where the file exists is copied. I go to the Explorer and try to paste, but the Paste option is not enabled. I am using the following code to copy the file to the clipboard:

Is it possible to transfer a file from Java and have it recognized by the system? If so, will you point me to documentation/example of how it can be done.
Thanks.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Getting and Setting Text on the System Clipboard
 
S Saunders
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Cindy Glass:
Getting and Setting Text on the System Clipboard

I appreciate the response. I can currently copy/paste a string, but would like to know if it is possible to paste a "file handle" from java, such that Windows would recognize it as a file and not as text. Currently, I have been unsuccessful at finding a solution.
Steve
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although I don't know the answer to your question, I wanted to point out that such an action is probably very dependant on the specific platform where it runs (Windows in this case). This seems to go against the platform-independant philosophy that drives Java development. I am sure that you could do this in C with the Windows API, but it seems to be somewhat contrary to the typical mindset of a Java programmer.
With that said, perhaps you can still find a way to do it. I wish you luck in your continued search.
Layne
 
S Saunders
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Layne,
You bring up a good point. I guess I hoped for a simple solution in Java. Thanks for the reminder, and I will begin looking at doing it with code outside of java.
Steve
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!