Downloading a file created in server using Java -


i trying download file given url. url not direct file url. when url provided in browser manually, prompt download/save.

for example, http://www.my-domain.com/download/type/salary/format/excel

i have no issues in url has file name directly in url. in above url, based on format , type, server generates file.

in java trying download file using below code. file created, content domain content , not actual excel data.

url url = new url("http://www.my-domain.com/download/type/salary/format/excel"); httpurlconnection connection = (httpurlconnection) url.openconnection();  float totaldataread = 0; bufferedinputstream in = new bufferedinputstream(connection.getinputstream()); fileoutputstream fos = new fileoutputstream("c:\\test.xls"); bufferedoutputstream bout = new bufferedoutputstream(fos, 1024);  byte[] data = new byte[1024]; int = 0;  while ((i = in.read(data, 0, 1024)) >= 0) {     totaldataread = totaldataread + i;     bout.write(data, 0, i); }  bout.close(); in.close(); 

the content whatever server sent url. can't client end. if contained javascript example won't executed.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -