概述
packagejavaapplication1;publicclassFTPSend{privateintport=2000;privateServeSocketserverSocket;privateExecutorServiceexecutorService;privatefinalintPOOL_SIZE=16;publicFTPS...
package javaapplication1;
public class FTPSend{
private int port=2000;
private ServeSocket serverSocket;
private ExecutorService executorService;
private final int POOL_SIZE=16;
public FTPSend() throws IOException{
serverSocket=new ServerSocket(port);
executorService=Executors.newFixedThreadPool(
Runtime.getRuntime().availableProcessors()*POOL_SIZE);
if(serverSocket!=null) System.out.printlin("服务器2启动");
else System.exit(0);
}
public void service(){
while(true){
Socket socket=null;
try{
socket=serverSocket.accept();
executorService.executor(new Handler(socket));
}catch(IOException e){e.printStackTrace();}
}
}
public static void main(String args[])throws IOException{
newFTPSend().service(); }
}
class Handler implements Runnable{
private Socket socket;
public Handler(Socket socket){
this.socket=socket; }
public void run(){
try{
OutputStream socketOut=socket.getOutputStream();
PrintWrtiter pw=new PrintWriter(new OutoutStream());
pw.println("输入学号和姓名");
InputStream socketIn=socket.getInputStream();
BufferedReader bf=new BufferedReader(new InputStreamReader(socketIn,"GBK"));
PrintWrite pwf=new PrintWriter(new FileOutputStream("login.txt",true),true);
pwf.println(bf.readLine());
String fileName="D: \kaoshi.txt";
InputStream fileRead = new FileInputStream(fileName);
byte[]buff = new bute[1024*2];
int len=fileRead.read(buff);
while(len!=-1){
socketOut.write(buff,0,len);
len=fileRead.read(buff);
}
fileRead.close();socketOut.close();System.out.println("File send over");
}catch(IOException e){e.printStackTrace();
}finally{
try{
if(socket!=null)socket.close();
}catch(IOException e){e.printStackTrace();}
}
}
}
加了,还是不行
展开
最后
以上就是明亮墨镜为你收集整理的java没有主方法怎么解决方案_java里显示,“类没有主方法”的全部内容,希望文章能够帮你解决java没有主方法怎么解决方案_java里显示,“类没有主方法”所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复