java里显示,“类没有主方法”
packagejavaapplication1;publicclassFTPSend{privateintport=2000;privateServeSocketserv...
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();}
}
}
}
加了,还是不行 展开
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();}
}
}
}
加了,还是不行 展开
8个回答
展开全部
//你自学看下我给你改的地方,其实都是写书写错误!
package javaapplication1;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class FTPSend{
private int port=2000;
private ServerSocket serverSocket;//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.println("服务器2启动");//printlin也错了应该是println,最后的“;”号是汉语的改为英文的
else System.exit(0);
}
public void service(){
while(true){
Socket socket=null;
try{
socket=serverSocket.accept();
executorService.execute(new Handler(socket));//executor应该是execute写错了吧
}catch(IOException e){e.printStackTrace();}
}
}
public static void main(String args[])throws IOException{
new FTPSend().service(); }//newFTPSend少了个空格
}
class Handler implements Runnable{
private Socket socket;
public Handler(Socket socket){
this.socket=socket; }
public void run(){
try{
OutputStream socketOut=socket.getOutputStream();
PrintWriter pw=new PrintWriter(socketOut);//OutoutStream个东西没有我帮你改为了socketOut
//PrintWrtiter 也 错了我帮你改为PrintWriter
pw.println("输入学号和姓名");
InputStream socketIn=socket.getInputStream();
BufferedReader bf=new BufferedReader(new InputStreamReader(socketIn,"GBK"));
PrintWriter pwf=new PrintWriter(new FileOutputStream("login.txt",true),true);//PrintWrite这个也错了吧。改为 PrintWriter
pwf.println(bf.readLine());
String fileName="D: \\kaoshi.txt";
InputStream fileRead = new FileInputStream(fileName);
byte[]buff = new byte[1024*2];//bute改为:byte
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();}
}
}
}
package javaapplication1;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class FTPSend{
private int port=2000;
private ServerSocket serverSocket;//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.println("服务器2启动");//printlin也错了应该是println,最后的“;”号是汉语的改为英文的
else System.exit(0);
}
public void service(){
while(true){
Socket socket=null;
try{
socket=serverSocket.accept();
executorService.execute(new Handler(socket));//executor应该是execute写错了吧
}catch(IOException e){e.printStackTrace();}
}
}
public static void main(String args[])throws IOException{
new FTPSend().service(); }//newFTPSend少了个空格
}
class Handler implements Runnable{
private Socket socket;
public Handler(Socket socket){
this.socket=socket; }
public void run(){
try{
OutputStream socketOut=socket.getOutputStream();
PrintWriter pw=new PrintWriter(socketOut);//OutoutStream个东西没有我帮你改为了socketOut
//PrintWrtiter 也 错了我帮你改为PrintWriter
pw.println("输入学号和姓名");
InputStream socketIn=socket.getInputStream();
BufferedReader bf=new BufferedReader(new InputStreamReader(socketIn,"GBK"));
PrintWriter pwf=new PrintWriter(new FileOutputStream("login.txt",true),true);//PrintWrite这个也错了吧。改为 PrintWriter
pwf.println(bf.readLine());
String fileName="D: \\kaoshi.txt";
InputStream fileRead = new FileInputStream(fileName);
byte[]buff = new byte[1024*2];//bute改为:byte
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();}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-07-11
展开全部
同学,你的代码N多地方拼错单词。。。。你main方法里 newFTPSend().service();这是什么?
new 后面要空格再后面吧,我拷了你代码下来,发现很多地方拼写错误,比如你run()里的try里的 PrintWrtiter pw=new PrintWriter(new OutoutStream());OutoutStream()是什么来的。。。。我改了后运行并不是没有main方法的错误哦,再后来发现 就是 service()方法里的 socket=serverSocket.accept();方法是阻塞方法来的,下面的代码是执行不了的。。。。
你是想做一个客户端与服务端的通信吧。。。你自己改改看吧!
new 后面要空格再后面吧,我拷了你代码下来,发现很多地方拼写错误,比如你run()里的try里的 PrintWrtiter pw=new PrintWriter(new OutoutStream());OutoutStream()是什么来的。。。。我改了后运行并不是没有main方法的错误哦,再后来发现 就是 service()方法里的 socket=serverSocket.accept();方法是阻塞方法来的,下面的代码是执行不了的。。。。
你是想做一个客户端与服务端的通信吧。。。你自己改改看吧!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
如果你要单独运行该类的话,该类必须含有这个方法:
public static void main(String args[]){
System.out.println("这就是主方法!");
}
public static void main(String args[]){
System.out.println("这就是主方法!");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没有main方法
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |