文件内容 UTF怎么传啊
import java.net.*;import java.io.*;
class socket
{
public static void main(String[] args)
{
ServerSocket s=null;
try
{
s=new ServerSocket(3456);
}
catch(IOException e)
{
}
while(true)
{
try
{
Socket s1=s.accept();
DataOutputStream dos=new DataOutputStream(s1.getOutputStream());
FileReader input=new FileReader("server.java");
BufferedReader br=new BufferedReader(input);
String str=br.readLine();
while(str!=null)
{
dos.writeUTF(str);
str=br.readLine();
}
dos.close();
s1.close();
}
catch(IOException e)
{
}
}
}
}
服务器端
-----------------------------------
import java.net.*;
import java.io.*;
class testClient
{
public static void main(String[] args)
{
try
{
Socket s=new Socket("127.0.0.1",3456);
DataInputStream dis=new DataInputStream(s.getInputStream());
FileWriter fw=new FileWriter("temp.txt");
PrintWriter bw=new PrintWriter(fw);
String s1=dis.readUTF();
while(s1!=null)
{
System.out.println(s1);
bw.println(s1);
s1=dis.readUTF();
}
bw.close();
dis.close();
s.close();
}
catch(ConnectException con)
{
System.out.println("cant connect");
}catch(IOException e)
{
System.out.println("can,t work");
e.printStackTrace();
}
}
}
客户端
----------------------
怎么什么都没有呢
大家帮忙啊 这里谢过了