package NET;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class TextClient2 {
/**
* @param args
*/
public static void main(String[] args) {
Socket s= null;
try {
s = new Socket("127.0.0.1",10006);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
BufferedReader bufr = null;
PrintWriter out = null;
try {
bufr = new BufferedReader(
new FileReader("d:\\demo.txt"));
out = new PrintWriter(s.getOutputStream(),true);
// DataOutputStream dos = new DataOutputStream(s.getOutputStream());
/*//定义时间标记
long time = System.currentTimeMillis();
// out.println(time);
dos.writeLong(time);
*/
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
String line = null;
try {
while((line=bufr.readLine())!=null){
out.println(line);
}
// out.close(); 这个地方为什么不能通过关闭这个socket的,输出流来结束文件的复制呢,s.shutdownOutput()不也是关闭操作码?
s.shutdownOutput();//关闭客户端的输出流,相当于给流中加入一个结束标记。
// out.println("over");
} catch (IOException e) {
e.printStackTrace();
}
BufferedReader bufIn=null;
String str=null;
try {
bufIn = new BufferedReader(new InputStreamReader(
s.getInputStream()));
str = bufIn.readLine();
System.out.println(str);
bufr.close();
s.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
|