Reputation: 1
is it possible to download file from database through browser (ex: mozilla,chrome) in java desktop application (non web app) ? can you explain me with an example code ?
thanks in advance,
Upvotes: 0
Views: 405
Reputation: 168825
Anything that is available through a browser should be available to a Java desktop app. At least unless the server (e.g. Google) goes to measures to block 'programmatic access'.
can you explain me with an example code?
Sure, adapted from the Java Sound info. page.
import java.net.URL;
import javax.swing.*;
import javax.sound.sampled.*;
public class LoopSound {
public static void main(String[] args) throws Exception {
// imagine a DB is preparing/serving this - same difference.
URL url = new URL(
"http://pscode.org/media/leftright.wav");
Clip clip = AudioSystem.getClip();
AudioInputStream ais = AudioSystem.
getAudioInputStream( url );
clip.open(ais);
clip.loop(-1);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(null, "Close to exit!");
}
});
}
}
Upvotes: 1
Reputation: 1108802
Use Desktop#browse()
wherein you just specify the URI of that file (exactly the one as you would enter in the address bar of a normal webbrowser).
Desktop.getDesktop().browse(new URI("http://example.com/download/file.ext"));
The other side has just to set Content-Disposition: attachment
on this response to force a Save As dialogue (and of course fill the response body with the necessary data from the DB).
Upvotes: 2