我有一个客户端服务器应用程序,图像发送成功,但由于标题中的错误,服务器无法完全接收它。这是我的代码:
服务器:public void upload()抛出IOException {
ws.Cells(1,1).Value
// **********************阅读图片********************* ************ //
DataInputStream dis = new DataInputStream (sock.getInputStream());
String str,extn = "";
str = dis.readUTF();
int flag=0,i;
for(i=0;i<str.length();i++)
{
if(str.charAt(i)=='.' || flag==1)
{
flag=1;
extn+=str.charAt(i);
}
}
运行方法:
if(extn.equals(".jpg") || extn.equals(".gif"))
{
File file = new File("RecievedImage"+str);
FileOutputStream fout = new FileOutputStream(file);
//receive and save image from client
byte[] readData = new byte[8];
while((i = dis.read(readData)) != -1)
{
fout.write(readData, 0, i);
if(flag==1)
{
System.out.println("Image Has Been Received");
flag=0;
}
}
fout.flush();
fout.close();
}
executorService.shutdown();
}
任何帮助?