Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

URLConnection create some problem

  Asked By: Boell    Date: Apr 01    Category: Java    Views: 514
  

pls see this code .my problem is that downloaded file is different
from the original file in other words i can't unzip the dowloaded
file .but in original file in server works fine

import java.lang.*;
import java.io.*;
import java.util.*;
import java.net.*;
import java.util.Date.*;
import java.util.jar.*;
import java.util.jar.*;
class jardownload
{
public static void main(String[] args)
{
URL hp=null;
URLConnection hpConn=null;
BufferedReader inpu=null;
//PrintWriter out1=null;

try
{
System.out.println("Down Loading Now ....");
hp =new URL
("http://saturn:8080/examples/downloadablefiles/jar1.jar");

hpConn.setRequestProperty("content-disposition",
"application/x-zip");

hpConn =hp.openConnection();
inpu = new BufferedReader(
new InputStreamReader(
hpConn.getInputStream()));

//out1= new PrintWriter(new BufferedWriter(new FileWriter
("c:/inbox/jar1.jar",true)));

FileOutputStream out1=new FileOutputStream
("c:/inbox/jar1.jar",true);
int bytesRead;
String line;






//byte[] buffer = new byte[1024];

while ((bytesRead = inpu.read()) != -1)
{
//out1.write
(buffer, 0, bytesRead);
out1.write
(bytesRead);
}

out1.close();
}catch(Exception e){}

}
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on URLConnection create some problem Or get search suggestion and latest updates.




Tagged: