🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #14890

Re: Java input en output streams

#14890
From: VdA
Date: Wed, 27 Dec 2000 18:35
70 lines
3040 bytes
nog een hint:

voer eens uit met
java -Dhttp.proxyHost=<jou_proxy> -Dhttp.proxyPort=<proxy_port> Download
ipv java Download

<hope this helps>

de groeten,
    VdA


"Marc De Smet" <madesmet@eduserv2.rug.ac.be> wrote in message
news:928lma$oub$1@inf6serv.rug.ac.be...
>
> Hallo,
>
> Ik moet een programma schrijven dat een bestand download.
> Ik moet hiervoor gebruik maken van URLConnection.
> Iemand enig idee wat er fout is met deze code?
> De code is compileerbaar. Het lokale bestand wordt aangemaakt maar blijft
leeg.
>
> Suggesties hoe ik het anders zou kunnen aanpakken zijn altijd welkom.
>
> Alvast bedankt,
> Marc
>
> // Er wordt vrij sterk gekeken naar mogelijke exceptions.
> // Er treedt geen enkele exceptie op!
>
>    URL url;
>         InputStream in;
>         try { url = new
URL("http://studwww.rug.ac.be/~madesmet/index.html"); }
>         catch (MalformedURLException e) {
>                 System.out.println("DownloadExtension: MalFormedURL " +
fn);
>                 return;
>                 }
>         try {   URLConnection conn = url.openConnection();
>                 in = conn.getInputStream(); }
>         catch (IOException e) {
>                 System.out.println("DownloadExtension: IOException");
>                 return;
>                 }
>
>         System.out.println("Stream opened for " + url.getFile());
>
>
>         try {
>            byte[] buf = {};
>            FileOutputStream fos = new FileOutputStream("output");
>            System.out.println("output aangemaakt");
>            while ((in.read(buf))>0) {
>                    System.out.println("in de lus..");
>                 fos.write(buf);
>                 }
>            System.out.println("zal alles sluiten nu..");
>            in.close();
>            fos.close();
>         }
>         catch (IOException e) {
>                 System.out.println("IOException");
>                 return;
>                 }
>
>         System.out.println("file written!");
>
>
Technical Details
Message-ID: <SDq26.2854$CK.89256@afrodite.telenet-ops.be>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news-x.support.nl!newsfeeds.belnet.be!news.belnet.be!afrodite.telenet-ops.be!not-for-mail
References: <928lma$oub$1@inf6serv.rug.ac.be>

Show Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII-7-bit
X-Google-Thread: fcea4,c6cb4a20ce0a4c47
X-Google-Attributes: gidfcea4,public
X-Google-ArrivalTime: 2000-12-27 10:35:31 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news-x.support.nl!newsfeeds.belnet.be!news.belnet.be!afrodite.telenet-ops.be!not-for-mail
From: "VdA" <vda@cryogen.com>
Newsgroups: be.comp.programming
References: <928lma$oub$1@inf6serv.rug.ac.be>
Subject: Re: Java input en output streams
Lines: 72
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2919.6700
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700
Message-ID: <SDq26.2854$CK.89256@afrodite.telenet-ops.be>
Date: Wed, 27 Dec 2000 18:35:30 GMT
NNTP-Posting-Host: 213.224.68.229
X-Complaints-To: abuse@pandora.be
X-Trace: afrodite.telenet-ops.be 977942130 213.224.68.229 (Wed, 27 Dec 2000 19:35:30 MET)
NNTP-Posting-Date: Wed, 27 Dec 2000 19:35:30 MET
Organization: Pandora - Met vlotte tred op Internet