File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes downloading a dll or a jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "downloading a dll or a jar" Watch "downloading a dll or a jar" New topic

downloading a dll or a jar

Mohammad Farhat
Ranch Hand

Joined: Nov 17, 2005
Posts: 51
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();
DataInputStream data = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
String line;
StringBuffer buf = new StringBuffer();
while ((line = data.readLine()) != null) {
buf.append(line + "\n");
BufferedWriter out = new BufferedWriter(new FileWriter("c:\\clib_jiio.dll"));

does the transfer corrupt the file?
how can we download a dll/jar properly?
Thanks guys,
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
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

Joined: Nov 17, 2005
Posts: 51
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:

URL url = new URL("");
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 = != -1) {
}catch(Exception e){

which i'm posting here if anyone would like to use it
btw, the code here i found on
I agree. Here's the link:
subject: downloading a dll or a jar
jQuery in Action, 3rd edition