import java.net.*;
import java.io.*;
public class ClientText {
public static void main(String[] args) throws Exception
{
Socket s=new Socket("169.254.91.182",10007);
BufferedReader br=new BufferedReader(new FileReader("C:\\Users\\Administrator\\Desktop\\数鸭子.txt"));
// BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
PrintWriter pw=new PrintWriter(s.getOutputStream(),true);
String line=null;
while((line=br.readLine())!=null)
{
pw.println(line);
}
pw.println("over");
BufferedReader b=new BufferedReader(new InputStreamReader(s.getInputStream()));
String st=b.readLine();
System.out.println(st);
s.close();
br.close();
}
}
---------------------------------------------------------------------------------------------------------------------------------------------
import java.io.*;
import java.net.*;
public class ServerText {
public static void main(String[] args) throws Exception
{
ServerSocket ss=new ServerSocket(10007);
Socket s=ss.accept();
String ip=s.getInetAddress().getHostAddress();
System.out.println(ip+"......conneted!");
BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter pw=new PrintWriter(new FileWriter("C:\\Users\\Administrator\\Desktop\\数鸭子1.txt"));
String line=null;
while((line=br.readLine())!=null)
{
if(line=="over")
break;
pw.println(line);
}
PrintWriter pw1=new PrintWriter(s.getOutputStream(),true);
pw1.write("文件复制成功!");
s.close();
ss.close();
pw.close();
pw1.close();
}
}
我这2个类是写在2个java文件中的,为什么运行没有结果啊,复制不过来??求解释! |
|