String path = "data/data/com.example.qqlogin/login.txt";
FileOutputStream fos = new FileOutputStream(path);
String data = number + "##" + password;
fos.write(data.getBytes());
fos.flush();
fos.close();
或者
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// /data/data/包名/files/aa.txt
// openFileOutput("aa.txt", Context.mode)
//私有文件
writeToLocal("private.txt",Context.MODE_PRIVATE);
//可读文件
writeToLocal("readable.txt", Context.MODE_WORLD_READABLE);
//可写文件
writeToLocal("writeable.txt", Context.MODE_WORLD_WRITEABLE);
//可读可写
writeToLocal("readable_writeable", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
}
private void writeToLocal(String fileName,int mode){
try {
FileOutputStream fos = openFileOutput(fileName, mode);
fos.write(("第一个程序写的数据:"+fileName).getBytes());
fos.flush();
fos.close();
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}