package FileTran;
import java.io.EOFException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import MyFrame.Myframe;
public class FileMsgthread
extends Thread {
private Myframe mf;
private byte[] b = null;
public FileMsgthread
(Socket sock, Myframe mf
) {
this.sock = sock;
this.mf = mf;
msg = mf.getPane().getContendjt().getText();
}
public void run() {
try {
li
= (List) this.
in.
readObject();
lb = li.subList(0, li.size() - 2);
int len
= (Integer) li.
get(li.
size() - 2);
+ this.sock.getInetAddress().getHostAddress()
+ " 发送文件:\n"+file);
if(judge==0){
this.jfc.setSelectedFile(this.fi);
this.jfc.showSaveDialog(mf);
this.fi=this.jfc.getSelectedFile();
}else{
return;
}
this.mf.getPane().getContendjt().setText(msg + "接收中.......\n");
int i = 0;
while (i < lb.size()) {
b = (byte[]) lb.get(i);
if (i == (lb.size() - 1)) {
out.write(b, 0, len);
out.flush();
break;
}
out.write(b);
out.flush();
i++;
}
this.mf.getPane().getContendjt().setText(msg + "文件接收完毕.....\n");
return;
// TODO Auto-generated catch block
// e.printStackTrace();
return;
// TODO Auto-generated catch block
// e.printStackTrace();
return;
} finally {
if (in != null) {
try {
in.close();
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (sock != null) {
try {
sock.close();
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (this.out != null) {
try {
this.out.close();
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
//源代码片段来自云代码http://yuncode.net