本人最近在做一个在android实现sim卡卡号绑定功能的实验,我是将绑定时用到的匹配文件存储在SD卡下,当我操作程序界面中的某一按钮控件后,可向相应的匹配文件中写入数据,但是我通过使用另外的一个按钮控件向文件写入其他内容后,在我重启系统后,我发现android模拟器下的文件中的内容全部为空,什么内容都没有了,请问一下大家这是什么原因呢?以下是我的部分操作代码,请大家指教。 Buttonrewrite.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
DataOutputStream dataout = null;
FileOutputStream fout = null;
// String data = "1354";
try
{
fout = new FileOutputStream("\\sdcard\\data.dat");
dataout = new DataOutputStream(fout);
try
{
Thread.sleep(1000);
}
catch(Exception ex)
{
}
dataout.writeBytes(imsi);
dataout.close();
fout.close();
}
catch(Exception ex)
{
Toast.makeText(Banding.this, "重新写入有错误", Toast.LENGTH_LONG).show();
}
AlertDialog.Builder Rewrite= new AlertDialog.Builder(Banding.this);
Rewrite.setTitle("关于重新写入号码")
.setMessage("重新写入成功")
.show();
}
});
ButtonSet.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
String config = "open";
FileOutputStream matchfile = null;
DataOutputStream dataout = null;
try
{
matchfile = new FileOutputStream("\\sdcard\\matchfile.dat");
dataout = new DataOutputStream(matchfile);
try
{
Thread.sleep(1000);
}
catch(Exception ex)
{
}
dataout.writeBytes(config); dataout.close();
matchfile.close();
}
catch(Exception ex)
{
Toast.makeText(Banding.this, "设置关闭错误", Toast.LENGTH_LONG).show();
}
AlertDialog.Builder DialogSet = new AlertDialog.Builder(Banding.this);
DialogSet.setTitle("关于绑定SIM卡")
.setMessage("开启绑定功能")
.show();
}
});
ButtonCancel.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
String config = "close";
FileOutputStream matchfile = null;
DataOutputStream dataout = null;
try
{
matchfile = new FileOutputStream("\\sdcard\\matchfile.dat");
dataout = new DataOutputStream(matchfile);
try
{
Thread.sleep(1000);
}
catch(Exception ex)
{
}
dataout.writeBytes(config);
dataout.close();
matchfile.close();
}
catch(Exception ex)
{
Toast.makeText(Banding.this, "设置开启错误", Toast.LENGTH_LONG).show();
}
AlertDialog.Builder DialogCancel = new AlertDialog.Builder(Banding.this);
DialogCancel.setTitle("关于绑定SIM卡")
.setMessage("关闭绑定功能")
.show();
}
});
{
public void onClick(View v)
{
DataOutputStream dataout = null;
FileOutputStream fout = null;
// String data = "1354";
try
{
fout = new FileOutputStream("\\sdcard\\data.dat");
dataout = new DataOutputStream(fout);
try
{
Thread.sleep(1000);
}
catch(Exception ex)
{
}
dataout.writeBytes(imsi);
dataout.close();
fout.close();
}
catch(Exception ex)
{
Toast.makeText(Banding.this, "重新写入有错误", Toast.LENGTH_LONG).show();
}
AlertDialog.Builder Rewrite= new AlertDialog.Builder(Banding.this);
Rewrite.setTitle("关于重新写入号码")
.setMessage("重新写入成功")
.show();
}
});
ButtonSet.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
String config = "open";
FileOutputStream matchfile = null;
DataOutputStream dataout = null;
try
{
matchfile = new FileOutputStream("\\sdcard\\matchfile.dat");
dataout = new DataOutputStream(matchfile);
try
{
Thread.sleep(1000);
}
catch(Exception ex)
{
}
dataout.writeBytes(config); dataout.close();
matchfile.close();
}
catch(Exception ex)
{
Toast.makeText(Banding.this, "设置关闭错误", Toast.LENGTH_LONG).show();
}
AlertDialog.Builder DialogSet = new AlertDialog.Builder(Banding.this);
DialogSet.setTitle("关于绑定SIM卡")
.setMessage("开启绑定功能")
.show();
}
});
ButtonCancel.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
String config = "close";
FileOutputStream matchfile = null;
DataOutputStream dataout = null;
try
{
matchfile = new FileOutputStream("\\sdcard\\matchfile.dat");
dataout = new DataOutputStream(matchfile);
try
{
Thread.sleep(1000);
}
catch(Exception ex)
{
}
dataout.writeBytes(config);
dataout.close();
matchfile.close();
}
catch(Exception ex)
{
Toast.makeText(Banding.this, "设置开启错误", Toast.LENGTH_LONG).show();
}
AlertDialog.Builder DialogCancel = new AlertDialog.Builder(Banding.this);
DialogCancel.setTitle("关于绑定SIM卡")
.setMessage("关闭绑定功能")
.show();
}
});
解决方案 »
- notification使用中跳转时的问题?
- Android开发:怎样由已知的packageName得到对应的PackageManager对象
- 菜鸟问题:怎样在Android(ArcGIS API for Android)程序中添加自己的地图
- 求教!多个类似项目如何整合成一个?
- 安卓开发中静态注册的问题。
- 在线等,一个 Run Configuration问题
- 请教
- XML文件分析,算法问题!求解决方案。。。
- android6.0 蓝牙遇到com.android.bluetooth进程终止
- 关于uiautomator,对textview的naf属性为True时怎么样获取内容
- [求助]android里如何获得短信中心的号码
- 关于横竖屏切换的状态保存
dataout.close();
另外,按照帮助文档的解释,flush()方法并不是必须的吧;