代码功能:在Android中,将变量存储在TXT文件中,并保存到本地sd卡根目录下。并且写入的东西不会被覆盖掉,而是不断添加。
//将ID和分数写入sd卡
try {
// 判断是否存在SD卡
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
// 获取SD卡的目录
File file = Environment.getExternalStorageDirectory();
FileOutputStream fileW = new FileOutputStream(file.getCanonicalPath() + "/cardRecoeds.txt",true);
fileW.write(Integer.toString(r).getBytes());
fileW.write(" : ".getBytes());
fileW.write(Integer.toString(myRecognizeResult[0]).getBytes());
fileW.write(" \n ".getBytes());
fileW.close();
}else{
Log.i("TestFile",
"SD card is not avaiable/writeable right now.");
}
} catch (Exception e) {
e.printStackTrace();
}