je fais:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| import java.net.*;
public class SourceViewer {
public static void main (String[] args) {
if (args.length > 0) {
try {
// Open the URLConnection for reading
URL u = new URL(args[0]);
URLConnection uc = u.openConnection();
InputStream in = uc.getInputStream();
// Chain a ProgressMonitorInputStream to the
// URLConnection's InputStream
ProgressMonitorInputStream pin
= new ProgressMonitorInputStream(null, u.toString(), in);
// Set the maximum value of the ProgressMonitor
ProgressMonitor pm = pin.getProgressMonitor();
pm.setMaximum(uc.getContentLength());
// Read the data
int c;
while ((c = pin.read()) != -1) {
System.out.print((char) c);
}
pin.close();
}
catch (MalformedURLException e) {
System.err.println(args[0] + " is not a parseable URL");
}
catch (InterruptedIOException e) {
// User cancelled. Do nothing.
}
catch (IOException e) {
System.err.println(e);
}
} // end if
// Since we brought up a GUI, we have to explicitly exit here
// rather than simply returning from the main() method.
System.exit(0);
} // end main
} // end SourceViewer |
en passant en argument:http://dlc.sun.com/jdk/jre-1_5_0_01-windows-i586-p.exe
mais le prog se bloque sur :
InputStream in = uc.getInputStream();
Partager