?? tcpclient_tang.java
字號:
package com.jk.net;
import java.net.*;
import java.io.*;
public class TCPclient_tang {
public static void main(String[] args) {
String address = "127.0.0.1";
int port = 8888;
Socket s = null;
InputStream is = null;
OutputStream os = null;
PrintWriter pw = null;
BufferedReader br = null;
try {
//1.獲得socket
s = new Socket(address,port);
//2.獲得輸入輸出流
os = s.getOutputStream();
//3.包裝輸出流
pw = new PrintWriter(new OutputStreamWriter(os,"UTF-8"),true);
//字節流到字符流的轉換
//true表示自動flush
//4.發送
pw.println("please give me your time now!");
//5.獲得輸入流
is = s.getInputStream();
//6.包裝
br = new BufferedReader(new InputStreamReader(is,"UTF-8"));
//7.接收
System.out.println(br.readLine());
//8.關閉
br.close();
is.close();
pw.close();
os.close();
s.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -