您的方法应如下。将额外的上下文作为参数。对于这种方法,您可以通过您的服务或活动
public static void save(String filename, MyObjectClassArray[] theObjectAr, Context ctx) { FileOutputStream fos; try { fos = ctx.openFileOutput(filename, Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(theObjectAr); oos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); }catch(IOException e){ e.printStackTrace(); } }


