我正在尝试使用openFileOutput函数但它不编译并且无法识别该函数.我正在使用android sdk 1.6.这是一个sdk问题吗?这是参数问题吗?
import java.io.FileOutputStream;
public static void save(String filename, MyObjectClassArray[] theObjectAr) {
FileOutputStream fos;
try {
fos = 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();
}
}
Run Code Online (Sandbox Code Playgroud)
nai*_*kus 57
您的方法应如下所示.将额外的Context作为参数.您可以通过此方法传递服务或活动
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();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
83984 次 |
| 最近记录: |