📄 filetransrv.java
字号:
import java.io.*;
import java.net.*;
public class filetransrv
{
public static void main(String args[])
{
int port;
ServerSocket ss;
try
{
ss=new ServerSocket(8050);
//System.out.println("Server Waiting For Client On Port"+ss.getLocalPort());
while(true)
{
Socket s=ss.accept();
//System.out.println("New Connection Accepted"+s.getInetAddress()+":"+s.getPort());
try
{
String str="";
int len;
String FileName="C://Program Files/Java/jdk1.5.0/bin/2.txt";
FileInputStream inFile=new FileInputStream(FileName);
OutputStream is=s.getOutputStream();
DataOutputStream outs=new DataOutputStream(is);
while((len=inFile.available())>0)
{
byte[] b=new byte[len];
int ch=inFile.read(b);
if(ch==-1)
break;
String st=new String(b);
str=str+st;
}
outs.writeUTF(str);
inFile.close();
s.close();
outs.close();
}
catch(IOException e)
{
System.out.println("unable to openfile"+e);
return;
}
}
}
catch(IOException e)
{
System.out.println(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -