本帖最后由 刘胜寒 于 2013-5-18 03:09 编辑
客户端:
import java.io.*;
import java.net.*;
class TcpuplodCilent {
public static void main(String[] args)throws Exception {
Socket s = new Socket("127.0.0.1",10010);
OutputStream os = s.getOutputStream();
//封装上传文件对象
File f = new File("d:\000.txt");
BufferedReader bfr = new BufferedReader(new FileReader(f));
String line = null;
while((line = bfr.readLine())!=null){
byte[] b = line.getBytes();
os.write(b);
}
}
}
服务端:
import java.io.*;
import java.net.*;
class TCPserverStore {
public static void main(String[] args) throws Exception {
//建立服务端套接字
ServerSocket ss = new ServerSocket(10010);
//建立侦听器,侦听客户端通信点.
Socket s = ss.accept();
//建立输入流.
InputStream in = s.getInputStream();
//读出来的信息保存到服务器打印在控制台上.
BufferedReader bfw = new BufferedReader(
new InputStreamReader(in));
String line = null;
while((line = bfw.readLine())!=null){
System.out.println(line);
}
}
}
我这个程序运行不出来 是哪里出错了呢 ? 补充下 这个程序的目的是将文件上传到服务端. |