Hello everybody,
I try to find out how to download any file from a URL that doesn't specify. For example:
http://translate.google.com/translate_tts?q=Daniweb
^^This URL directs to an .mp3 file, which is the spoken text by Google Translate.
I have this code already, but it helps only when I use URL with the name of the file, such as:
http://google.com/undefined.pdf
(THIS URL IS A MADE-UP)
package Download;
import java.io.*;
import java.net.*;
public class SampleFile
{
public static void main(String args[]) throws IOException
{
java.io.BufferedInputStream in = new java.io.BufferedInputStream(new
java.net.URL("http://bdonline.sqe.com/documents/testplans.pdf").openStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream("testplans.pdf");
java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
byte[] data = new byte[1024];
int x=0;
while((x=in.read(data,0,1024))>=0)
{
bout.write(data,0,x);
}
bout.close();
in.close();
}
}
Any help will be appreciated, Thanks!