📄 server.java
字号:
package ftp;
import java.net.*;
import java.io.*;
import javax.swing.*;
public class server
{
public static void main(String []args)
{
DataInputStream din;
DataOutputStream dout;
try{
ServerSocket ss=new ServerSocket(21);
Socket s=ss.accept();
if(s!=null)
System.out.println("ok");
else
System.out.println("error");
InputStream in=s.getInputStream();
OutputStream out=s.getOutputStream();
din=new DataInputStream(in);
dout=new DataOutputStream(out);
//BufferedReader buf=new BufferedReader(new InputStreamReader(in));
String str=din.readUTF();
File f=new File(str);
String mu[]=f.list();
int len=mu.length;
String legth=Integer.toString(len);
dout.writeUTF(legth);
for(int i=0;i<len;i++)
{
dout.writeUTF(mu[i]);
}
while(true)
{
String name=din.readUTF();
String pathname=str+name;
FileInputStream file=new FileInputStream(pathname);
int i;
int count=0;
StringBuffer buf=new StringBuffer();
while((i=file.read())!=-1)
{count++;}
String l=Integer.toString(count);
dout.writeUTF(l);
file.close();
FileInputStream fileout=new FileInputStream(pathname);
for(int j=0;j<count;j++)
{i=fileout.read();
out.write(i);}
String wenjian=din.readUTF();
int ll=i=Integer.parseInt(din.readUTF());
String spath=din.readUTF();
String sname=spath+wenjian;
FileOutputStream sfiletext=new FileOutputStream(sname);
for(int j=0;j<ll;j++)
{sfiletext.write(in.read());}
}
}catch(Exception e){System.out.println("出错了");}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -