I will second that, you might be having a DNS issue at the location you tried earlier. See if you can access http://java.sun.com from that machine which is running this code. So, incase you are running the code from some remote UNIX/Linux box, run it from that box and not the client machine.
Not really, the buffer size doesn't really matter. A larger buffer size might improve the speed of your transfer in some cases, you could try it. But the real problem here is that your code is wrong. Here's your copying loop:
So what you do is, you call the read() method. It returns the number of bytes it read, which may be any number between 0 and 1024. If it returns -1 then you're at EOF so you want to exit, which you do.
Now you're inside the loop and you know that some number of bytes were read. But you threw away the exact number and you're writing 1024 bytes regardless. One day this is going to come back and bite you.
"UnknownHostException" means that your computer can't find the numeric IP address for this machine name. Generally the computer has to ask something called a "DNS server" for this information. As someone said above, this sounds like a problem with your DNS server -- meaning your local network or your ISP is having a problem. In any case, it's completely unrelated to your Java code, which is fine (with Paul's changes, of course.) Talk to your local network administrator to get this straightened out.
UnknownHostException means that the name you're using for the server is unknown to your computer, whether the server is across the Internet or across the room. This has nothing to do with your code, and everything to do with your computer/network configuration. You need to talk to your local network techs to help you sort this out -- there's nothing anybody here can do.
And if you told us right away that the problem was not with downloading a file from java.sun.com, but from something on your own LAN, then we would have reached this conclusion much sooner!
Can you explain what you were looking at before and what you're looking at now, and how they differ? And please: if you were looking at the file in a browser before, for example, tell us that. Don't tell us something completely different, like you were doing earlier in the thread. Just the facts, please.
For example just take a bank statement its a simple txt file with proper alignment (newline, spacing) like month, date credit and debit. After downloading the file to client machine it seems to be mis alignment(everything came to single line with trimed spaces)
Anyway to copy the file directly from the server with proper alignment
Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad?