/**
* 上传图片客户端
* @author 黑马_王康
*
*/
public class PicThreadClient implements Runnable{
private Socket s;
PicThreadClient(Socket s){
this.s = s;
}
String ip = s.getInetAddress().getHostAddress();
@Override
public void run() {
try {
int count = 1;
System.out.println(ip+"....connected");
InputStream in = s.getInputStream();
File file = new File(ip+"("+(count)+")"+".jpg");
while(file.exists()){
file = new File(ip+"("+(count++)+")"+".jpg");
}
FileOutputStream fos = new FileOutputStream(file);
byte[] buf = new byte[1024];
int len = 0;
while((len=in.read(buf))!=-1){
fos.write(buf,0,len);
}
s.shutdownOutput();
OutputStream out = s.getOutputStream();
out.write("恭喜,上传成功!".getBytes());