下面的这个代码为什么会一直等待呢?虽然复制文件的功能实现了。
import java.net.*;
import java.io.*;
class Send
{
public static void main(String[] args)throws Exception
{
Socket s=new Socket("192.168.0.104",5002);
BufferedReader br=
new BufferedReader(new FileReader("wo.java"));
BufferedWriter bwout=
new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
BufferedReader brin=
new BufferedReader(new InputStreamReader(s.getInputStream()));
String str=null;
while((str=br.readLine())!=null)
{
bwout.write(str);
bwout.newLine();
bwout.flush();
}
String in=brin.readLine();
System.out.println(in);
br.close();
s.close();
}
}
class Rece
{
public static void main(String[] args)throws Exception
{
ServerSocket ss=new ServerSocket(5002);
Socket s=ss.accept();
InputStream is=s.getInputStream();
BufferedReader brin=
new BufferedReader(new InputStreamReader(s.getInputStream()));
BufferedWriter bw=
new BufferedWriter(new FileWriter("d:\\c.txt"));
BufferedWriter bwout=
new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
String str=null;
String name=s.getInetAddress().getHostAddress();
while((str=brin.readLine())!=null)
{
bw.write(str);
bw.newLine();
bw.flush();
}
System.out.println(name);
bwout.write("上传成功!");
bwout.newLine();
bwout.flush();
s.close();
}
}
|
|