I have an mp3
link i want to download from java just for testing. Here is what i code to do that
private void saveFile() throws Exception{
System.out.println("Opening InputStream.");
InputStream is = fileUrlConnection.getInputStream();
System.out.println("Total: "+is.available()+" bytes");
FileOutputStream fos = new FileOutputStream(new File("hello.mp3"));
byte[] buffer = new byte[1024];
while (is.read(buffer)!= -1) {
fos.write(buffer);
}
is.close();
fos.close();
}
Above method throws an exception after a number of calls.
java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.jwc.FileSaver.saveFile(FileSaver.java:24)
at com.jwc.FileSaver.run(FileSaver.java:39)
at java.lang.Thread.run(Unknown Source)