为什么第一个程序能正常运行,第2个程序会报错
try{
while(true)
System.out.println(dis.readUTF());
}
catch (EOFException e) {
System.out.println("Client closed.");
System.exit(-1);
} catch (IOException e) {
e.printStackTrace();
System.out.println();
} finally {
try {
if (s != null)
s.close();
if (dis != null)
dis.close();// 当客户端关闭时应关闭服务器端的Socket.
} catch (IOException e) {
e.printStackTrace();
}
}
while(true)
{
try{
System.out.println(dis.readUTF());}
catch (EOFException e) {
System.out.println("Client closed.");
System.exit(-1);
} catch (IOException e) {
e.printStackTrace();
System.out.println();
} finally {
try {
if (s != null)
s.close();
if (dis != null)
dis.close();// 当客户端关闭时应关闭服务器端的Socket.
} catch (IOException e) {
e.printStackTrace();
}
}
}
while(true)
{
try{
System.out.println(dis.readUTF());} catch (EOFException e) {
System.out.println("Client closed.");
System.exit(-1);
} catch (IOException e) {
e.printStackTrace();
System.out.println();
} finally {
try {
if (s != null)
s.close();
if (dis != null)
dis.close();// 当客户端关闭时应关闭服务器端的Socket.
} catch (IOException e) {
e.printStackTrace();
}
}
}
1、将代码进行良好的格式化,以方便阅读。
2、在发帖文本框的上方单击“#”按钮,选择 Java
3、将代码粘贴到【code=Java】和【/code】之间。发出来的帖子就会是下面的效果:public class Hello { // 程序入口
public static void main(String[] args) {
System.out.println("Hello!");
}
}