简体   繁体   中英

Can you download a file (picture) from a java dialog box application?

I'm trying to code in a download in my java application. Basically, the user inputs their personal information, which is sent through file i/o to a text document. Then the next step is to have a series of buttons or links that corresponds to a certain download. For instance, button1=file1, button2=file2, and so on. I need it to download a picture. Is this possible through a dialog box? I'm running the application through a website. Any help is appreciated!

You can download a file from a URL using URLConnection . You can have your dialog box display the choices then choose a URL depending on what button they pressed, and use the URLConnection (via .connect() and .getInputStream() ) to read the data, which you can then write out to a file or do whatever you want with.

You say you are running it through a web site, so I assume this is an applet. Bear in mind that if it is an unsigned applet you can only download files from the server that the applet is on. If you need to download from anywhere, you will need to sign your applet, or use something that isn't an applet.

Also, since you are running it through a web site, if it's appropriate perhaps a different approach is to just redirect the user to the URL of the file and let their browser take care of the download.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM