Java ProgressMonitorInputStream类的一个问题,望高手解答。。

软件和网站开发以及相关技术探讨
回复
sf0212
帖子: 1
注册时间: 2009-03-05 19:44

Java ProgressMonitorInputStream类的一个问题,望高手解答。。

#1

帖子 sf0212 » 2009-03-05 19:52

最近在看的一本IO书上有段代码(如下), 运行后却没有相应的Progress Dialog 跳出来, 不知道哪出问题了, 希望有高手能帮下, 谢谢~
import java.net.*;
import java.io.*;
import javax.swing.*;
public class MonitoredSourceViewer {
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
for (int c = pin.read(); c != -1; c = pin.read( )) {
System.out.print((char) c);
}
pin.close( );
}
catch (MalformedURLException ex) {
System.err.println(args[0] + " is not a parseable URL");
}
catch (InterruptedIOException ex) {
// User cancelled. Do nothing.
}
catch (IOException ex) {
System.err.println(ex);
}
} // 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 MonitoredSourceViewer
回复