这是一个使用TCP通讯下载一个文件的方法,现在我想使用一个JDialog窗口Loading显示文件下载的进度,
此时我的方法是
        System.out.println("A");
        Loading.main(null);     //打开进度条窗口
        System.out.println("B");
        getTCPMessage(file, name);  //调用下载方法
        System.out.println("C");
但结果是,程序首先输出A和B,然后等一会(下载时间)下载完成后输出C
       但是进度条窗口却是在输出C,也就是下载已经完成时才显示,
为什么?????????????????public void getTCPMessage(File file, String name) {
// 得到文件的位置(上传者ip和路径)
String[] m = name.split(" ");
try {
Socket s = new Socket(m[1], 8080);
InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream(); // 将文件的路径发送给服务器(上传者)
out.write(m[0].getBytes());
out.flush(); // 得到文件的实际大小
byte[] b1 = new byte[1000];
in.read(b1);
String length = new String(b1).trim();
long size = Long.parseLong(length); // 发送确认消息,通知服务器开始传文件
out.write("OK!".getBytes());
out.flush(); // 开始接收文件
byte[] b2 = new byte[10 * 1024 * 1024];
FileOutputStream fout = new FileOutputStream(file.getPath() + "\\"
+ new File(m[0]).getName());
int len = 0;
long add = 0;
while ((len = in.read(b2)) != -1) {
add += len;
fout.write(b2, 0, len);
if (add == size) {
break;
}
}
fout.flush();
fout.close(); in.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}