日期:2014-05-20  浏览次数:20779 次

try和catch语句
try{
      s=new Socket("192.168.0.17",port);
     InputStream is=s.getInputStream();

    DataInputStream dis=new DataInputStream(is);

File file=new File("d:/Agenda/Agenda.xml");
FileOutputStream fw=new FileOutputStream(file);
int b=0;
while((b=dis.read())!=-1){
fw.write(b);
}
dis.close();
s.close();

}catch(IOException e){
int i=JOptionPane.showConfirmDialog(null, "服务器没开","标题",JOptionPane.DEFAULT_OPTION);
while(i==0)
{

}
}
要怎么写catch里面,可以回到try中第一个语句,循环执行,知道我的服务器开启
------解决方案--------------------
int i=0; // 重连标志
do{
  try{
      s=new Socket("192.168.0.17",port);
       ...
      i=1; // 连接成功就别再连了
   }catch(IOException e){
      int i=JOptionPane.showConfirmDialog(null, "服务器没开","标题",JOptionPane.DEFAULT_OPTION);
   }
}while(i==0); // 循环移动到这里