• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

downloading a dll or a jar

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
i am trying to download dll files to the client's machine, so i simply created a URL object, read the bytes, and written them to the client's machine, yet they won't work
here is the code:

URLConnection conn = myURL.openConnection();
conn.connect();
DataInputStream data = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
String line;
StringBuffer buf = new StringBuffer();
while ((line = data.readLine()) != null) {
buf.append(line + "\n");
}
data.close();
BufferedWriter out = new BufferedWriter(new FileWriter("c:\\clib_jiio.dll"));
out.write(buf.toString());
out.close();

does the transfer corrupt the file?
how can we download a dll/jar properly?
Thanks guys,
Mohammad
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DataInputStream is for reading Java primimitives from a stream, while Writers are for writing character-oriented data; both make assumptions about the data they're dealing with, and are inappropriate for reading/writing binary data. Use BufferedIn[Out]putStream instead.
 
Mohammad Farhat
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ulf,
you were correct about the classes, in fact they do change some bytes (i compared the files, and noticed the differences)
i used the following code instead:

try{
URL url = new URL("http://cstation6.compressus.com:8080/eStation/clibwrapper_jiio.jar");
URLConnection connection = url.openConnection();
InputStream stream = connection.getInputStream();
BufferedInputStream in = new BufferedInputStream(stream);
FileOutputStream file = new FileOutputStream("d:\\version to replace\\clibwrapper_jiio.jar");
BufferedOutputStream out = new BufferedOutputStream(file);
int i;
while ((i = in.read()) != -1) {
out.write(i);
}
out.flush();
}catch(Exception e){
System.out.println("Error:"+e.getMessage());
}

which i'm posting here if anyone would like to use it
btw, the code here i found on
http://www.jguru.com/faq/view.jsp?EID=13198
Best,
Mohammad
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic