A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

import java.io.*;
import java.net.*;
class TextClient
{
public static void main(String[]args) throws Exception
{
Socket s=new Socket("192.168.1.102",10006);

BufferedReader  bufr=new BufferedReader(new FileReader("half.txt"));
PrintWriter out =new PrintWriter(s.getOutputStream(),true);
DataOutputStream dos=new DataOutputStream(s.getOutputStream());

long time=System.currentTimeMillis();
dos.writeLong(time);
String line =null;
while((line=bufr.readLine())!=null)
{
out.println(line);
}
dos.writeLong(time);
BufferedReader bufIn=new BufferedReader(new InputStreamReader(s.getInputStream()));
String str=bufIn.readLine();
System.out.println(str);
bufr.close();
s.close();
}
}
class TextServer
{
public static void main(String[]args)throws Exception
{
ServerSocket ss=new ServerSocket(10006);
Socket s=ss.accept();
DataInputStream dis=new DataInputStream(s.getInputStream());
long lg=dis.readLong();
BufferedReader bufIn=new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter out =new PrintWriter(new FileWriter("half1.txt"),true);
String line=null;
while((line=bufIn.readLine())!=null)
{
if(Long.parseLong(line)==lg)/////////////////////////////这样判断结束标记为什么不对啊????????????????????????
break;
out.println(line);
}
PrintWriter pw=new PrintWriter(s.getOutputStream(),true);
pw.println("上传成功");
out.close();
s.close();
ss.close();
}
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马