⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcpclient.java

📁 这是一个用java编写的模拟FTP的程序
💻 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 + -