This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm just wondering, is there some way in java to upload a file to the internet?
I have one of those free web pages (you know, with the advertisements). Anyway, the way I usually upload a file, is I go to the internet site of my page and click a button and choose a file and then click another button to upload it. But even though I want to upload a lot of files, I can upload only one file at a time. So I have to spend hours just clicking file icons. So I wonder, is there any way to write a java program that will do this for me?
One way this can be done is to to write a java program that will start up the internet browser and click buttons and click items in a list. I don't know if java programs can do that or not.
A more direct way, I suppose, is to write a program that will upload files directly, without even needing a browser. But I guess I would need some special password or access or something.
Maybe there is some other way to do it. I don't know. I've written a lot of java, but I'm clueless about how java works on the internet.
Rob Prime wrote:Check out Apache's HttpClient library.
Yep, this is the code to use. But don't think of it as "pressing buttons". That's what you have to do to make a browser upload a file, but what the browser is actually doing is sending HTTP requests and receiving HTTP responses. Your task is to identify the requests being sent and to replicate them in your Java code. The HttpClient library helps you to do that without also having to learn the tedious details of the HTTP protocol.
Joined: Jun 23, 2010
You could write a java applet that would run on the client end. You may have to resort to FTP by doing so (someone please confirm - I don't have much experience writing applets)