您的位置:首页 > 其它

安卓中创建别的应用程序可以读写的文件

2016-07-04 22:07 295 查看
public class MainActivity
extends Activity {

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

try {

/*得到一个文件的输出流,文件的位置/data/data/包名/files/haha.txt

 * File file = new File(getFilesDir(),"haha.txt");

FileOutputStream fos = new FileOutputStream(file);*/

FileOutputStream fos = openFileOutput("readable.txt",
MODE_WORLD_READABLE);

fos.write("dafa".getBytes());

fos.close();

fos = openFileOutput("writeable.txt",
MODE_WORLD_WRITEABLE);

fos.write("dafa".getBytes());

fos.close();

fos = openFileOutput("public.txt",
MODE_WORLD_WRITEABLE+MODE_WORLD_READABLE);

fos.write("dafa".getBytes());

fos.close();

fos = openFileOutput("private.txt",
MODE_PRIVATE);

fos.write("dafa".getBytes());

fos.close();

} catch (Exception e) {

e.printStackTrace();

}

}

 

 

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: