做一项目,其中有一部分要求文件自动上传到服务器,传送完成后要求对文件进行验证,然后告知客户端文件是否上传成功,我的问题是:当文件传完后,服务器要给客户端反馈信息,就是发送个success OR fail,但是出现SOCKET CLOSE的异常,不知如何解决源码如下:(摘取了部分,应该可以运行)服务器:public class FHUpload { //服务器的监听端口
private static final int PORT_FH = 3000; //将上传过来的文件传到c:\\supervision\\Upload_fh\\Upload_fh_jar下
private static final String FILEDIR_UPLOAD_FH_JAR = "c:\\supervision\\Upload_fh\\Upload_fh_jar\\"; public static void main(String[] args) throws IOException 
{
ServerSocket ss = new ServerSocket(PORT_FH);
System.out.println("服务器监听中......");
System.out.println("客户端应该连接到端口: "+ss.getLocalPort());
File uploadFileDir = new File(FILEDIR_UPLOAD_FH_JAR);
if(!uploadFileDir.exists())
uploadFileDir.mkdir();
try
{
Socket yhywclient = ss.accept();
System.out.println("客户端"+yhywclient.getInetAddress().getHostName()+" 连接请求被接受.");
try
{
DataInputStream dis = new DataInputStream(new BufferedInputStream(yhywclient.getInputStream()));
//接收文件名
String fileName = dis.readUTF();
System.out.println("filename="+fileName);
//接收文件长度
long fileSize = dis.readLong();
System.out.println("fileSize="+fileSize);

File uploadFile = new File(uploadFileDir,fileName);
DataOutputStream dos1= new DataOutputStream(new BufferedOutputStream(new FileOutputStream(uploadFile)));

int buffersize = 1024;
byte[] buf = new byte[buffersize];
int ch;
while((ch=dis.read(buf))!=-1)
{
dos1.write(buf,0,ch);
}
dos1.flush();
System.out.println("***************************");
System.out.println("    服务器文件接受完毕     ");
System.out.println("***************************");
dos1.close();
dis.close(); System.out.println("***************************");
System.out.println("    验证过程省略    ");
System.out.println("***************************"); //错误在这里
DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(yhywclient.getOutputStream()));
dos.writeUTF("success");
dos.close();


}finally{
yhywclient.close();
}
}finally{
ss.close();
}



}}----------------------------------------------------------------------------------------------------------
客户端:public class YHYWUpload
{
// 服务器的监听端口
private static final int PORT_FH = 3000;
// 将要上传的文件放在c:\\supervision\\Upload_yhyw\\Upload_yhyw_put下
private static final String FILEDIR_UPLOAD_TXT = "c:\\supervision\\Upload_yhyw\\Upload_yhyw_put\\test.txt";

public static void main(String[] args) throws IOException
{

Socket fhserver = new Socket(InetAddress.getLocalHost(),PORT_FH);

try
{
File fileListJar = new File(FILEDIR_UPLOAD_TXT);
String fileName = fileListJar.getName();
System.out.println("将要上传的文件名:"+fileName.toString());
long fileSize = fileListJar.length();
System.out.println("将要上传的文件长度:"+fileSize);


DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(fhserver.getOutputStream()));
dos.writeUTF(fileName);
dos.flush();
dos.writeLong(fileSize);
dos.flush();
DataInputStream dis1 = new DataInputStream(new BufferedInputStream(new FileInputStream(fileListJar)));


int bufferSize = 8192;
byte[] buf = new byte[bufferSize]; 
int ch;
while((ch=dis1.read(buf))!=-1)
{
dos.write(buf,0,ch);
}

dos.flush(); 
dis1.close();

System.out.println("********************");
System.out.println("    文件上传完毕     ");
System.out.println("********************");
dos.close();

DataInputStream dis = new DataInputStream(new BufferedInputStream(fhserver.getInputStream()));
System.out.println("dis.readUTF()="+dis.readUTF());
if(dis.readUTF().equals("success"))
{
System.out.println("文件上传成功");
}
else{
System.out.println("文件上传失败");
}

}catch (Exception e) {
System.out.println("文件传递失败");
e.printStackTrace();
}
finally{
fhserver.close();
System.out.println("fhserver.close");
}


}
}