我正在编写一个自定义协议。我有一个命令名称,代码如下所示。
if(commandString.equals("PUT")){
File f = new File(currentFolder, "test.txt");
if(!f.exists())
f.createNewFile();
FileOutputStream fout = new FileOutputStream(f);
long size = 150;
long count = 0;
int bufferLeng = 0;
byte[] buffer = new byte[512];
while((bufferLeng = dis.read(buffer))>0) //dis is a data input stream.
{
count =+ bufferLeng;
fout.write(buffer);
}
System.out.println("All Good");
fout.flush();
fout.close();
}
该命令由客户端发送到服务器,如下所示pWriter.println("PUT");
。现在我运行它,它确实创建了文件test.txt
,但随后被冻结,服务器不显示 All Good 消息。为什么会这样?什么是简单的解决方法?
服务器和客户端工作!
谢谢