首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

这个异常实在不知道哪里,括号没少啊

2013-07-01 
这个错误实在不知道哪里,括号没少啊!import java.io.IOExceptionimport java.net.*import java.io.*pub

这个错误实在不知道哪里,括号没少啊!

import java.io.IOException;
import java.net.*;
import java.io.*;
public class ChatServer {
  public static void main(String[]args){
  boolean falg = true;
  ServerSocket ss = null;
  Socket s = null; 
  try {
 ss = new ServerSocket(8888);
  }catch(IOException e){
  e.printStackTrace(); 
  }
while(falg){

   boolean bfalg = false;
   s = ss.accept();
System.out.print("服务器启动了");

      try{
          bfalg = true;
          DataInputStream dis = new DataInputStream(s.getInputStream());
          while(bfalg){
          String str = dis.readUTF();
          System.out.println(str);
          }
          dis.close();
          s.close();
}
}
catch (IOException e) {

e.printStackTrace();
}
  }
  
}

[解决办法]

package com.lzz.test;

import java.io.IOException;
import java.net.*;
import java.io.*;

public class ChatServer {
public static void main(String[] args) {
boolean falg = true;
ServerSocket ss = null;
Socket s = null;
try {
ss = new ServerSocket(8888);
} catch (IOException e) {
e.printStackTrace();
}
while (falg) {

boolean bfalg = false;
s = ss.accept();
System.out.print("服务器启动了");

try {
bfalg = true;
DataInputStream dis = new DataInputStream(s.getInputStream());
while (bfalg) {
String str = dis.readUTF();
System.out.println(str);
}
dis.close();
s.close();
} catch (IOException e) {

e.printStackTrace();
}
}

}
}

正确的应该是这样的,仔细对照着看吧
[解决办法]
看看吧,一处多一个,最后少一个:

import java.net.*;
import java.io.*;

public class Test {
public static void main(String[] args){
  boolean falg = true;
  ServerSocket ss = null;
  Socket s = null; 
  try {
  ss = new ServerSocket(8888);


  }catch(IOException e){
  e.printStackTrace(); 
  }
  while(falg){
  boolean bfalg = false;
  try {
s = ss.accept();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
  System.out.print("服务器启动了");

  try{
          bfalg = true;
          DataInputStream dis = new DataInputStream(s.getInputStream());
          while(bfalg){
          String str = dis.readUTF();
          System.out.println(str);
          }
          dis.close();
          s.close();
  
  }catch (IOException e) {
  e.printStackTrace();
  }
  }
}
}

热点排行