2 annbnncnnd AnnBnnCnnD 于 2013.01.17 11:19 提问

保存游戏时报出异常:FileNotFoundException

在保存android游戏的时候,报出异常:FileNotFoundException。游戏通过模拟器在windows中玩,不知道怎么解决这个异常。

FileOutputStream saveStream;
ObjectOutputStream savePlayerObject = null;
String destinationFile = player1.getName() + ".txt";

try
{
   saveStream = new FileOutputStream(destinationFile);    
   savePlayerObject = new ObjectOutputStream(saveStream);   
   savePlayerObject.writeObject(player1);
}

catch(FileNotFoundException ex)
{
   Toast toast = Toast.makeText(getApplicationContext(), "Save Failed", Toast.LENGTH_LONG);
   toast.show();
}


catch(IOException ex)
{
   Toast toast = Toast.makeText(getApplicationContext(), "Save Failed", Toast.LENGTH_LONG);
   toast.show();
}


finally
{
   try
   {
      if(savePlayerObject !=null)
      {
         savePlayerObject.flush();    
         savePlayerObject.close();   
         Toast toast = Toast.makeText(getApplicationContext(), "Thank-You For Playing, See You Soon", Toast.LENGTH_LONG);
         toast.show();   
         System.exit(0);   
      }
   }

   catch(IOException ex)
   {
      Toast toast = Toast.makeText(getApplicationContext(), "Save Failed", Toast.LENGTH_LONG);
      toast.show();
   }
}

1个回答

gamefinity
gamefinity   Rxr 2015.06.17 07:16

是不是没有给模拟器一个TF卡?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!