写文件
写入内部存储:
public Boolean SaveDataToRom(String name, String pwd){ Boolean flag = false; try{ String content = name+":"+pwd; FileOutputStream fos = context.openFileOutput("data.txt", Context.MODE_WORLD_WRITEABLE|Context.MODE_WORLD_READABLE); fos.write(content.getBytes()); fos.flush(); fos.close(); flag = true; } catch (Exception e) { // TODO: handle exception e.printStackTrace(); }finally{ return flag; } }
写入sdcard:
public Boolean SaveDataToSDCard(String name, String pwd){ Boolean flag = false; try{ String content = name+":"+pwd; if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){ FileOutputStream fos = new FileOutputStream(new File(Environment.getExternalStorageDirectory(),"test.txt")); fos.write(content.getBytes()); fos.flush(); fos.close(); flag = true; }else{ return flag; } } catch (Exception e) { // TODO: handle exception e.printStackTrace(); }finally{ return flag; } }