package FileTran;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import MyFrame.Myframe;
public class FileClient
extends Thread {
private Myframe mf;
public FileClient(Myframe mf) {
this.mf = mf;
this.msg = mf.getPane().getContendjt().getText();
this.
ip = (String) mf.
getPane().
getIpjt().
getSelectedItem();
}
public void run() {
this.
jfc.
setFileSelectionMode(JFileChooser.
FILES_AND_DIRECTORIES);
int reval=this.jfc.showOpenDialog(mf);
fi=this.jfc.getSelectedFile();
}else if(reval==1){
return;
}else{
return;
}
this.mf.getPane().getContendjt().setText(msg + "发送中.......\n");
String[] file
= fi.
toString().
split("\\\\",
-1);
byte[] b = new byte[10240];
try {
client
= new Socket(this.
ip,
9500);
int l = 0;
int len = 0;
byte[] a = null;
while ((l = in.read(b)) != -1) {
a = new byte[1024];
a = b.clone();
len = l;
li.add(a);
}
li.add(len);
li.add(file[file.length - 1]);
out.writeObject(li);
out.flush();
this.mf.getPane().getContendjt().setText(msg + "文件发送完毕.....\n");
// TODO Auto-generated catch block
return;
// TODO Auto-generated catch block
// e.printStackTrace();
return;
} finally {
if (out != null) {
try {
out.close();
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (client != null) {
try {
client.close();
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (in != null) {
try {
in.close();
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
//源代码片段来自云代码http://yuncode.net