📄 tcpclient.java
字号:
import java.net.*;
import java.io.*;
public class TcpClient
{
public static void main(String args[])
{
String host="127.0.0.1";
int port=2000;
try
{
Socket client = new Socket (host, port);
System.out.println ("Connection established" +
"\nInput file Name : ");
BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
String fileName = bin.readLine();
PrintStream pout = new PrintStream (client.getOutputStream());
pout.println(fileName);
pout.flush();
InputStream in = client.getInputStream();
FileOutputStream fout = new FileOutputStream("a.dat");
int i = 0;
while ((i=in.read())!=-1)
{
fout.write(i);
}
System.out.println ("OK!");
client.close();
}
catch (IOException ioe)
{
System.err.println ("Error " + ioe);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -