package com.gaozewen.createfile;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import java.io.FileOutputStream;
public class MainActivity extends AppCompatActivity {
/**
* adb kill-server
* adb start-server
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 创建一个文件,这个文件可以让别的应用程序读写
// 当创建的文件的保存路径,是当前应用程序目录下 子目录时,可以不用添加权限,即使是6.0以上
// linux 文件权限
// d rwx rw- r--
// 第一个 - 文件 d 目录 l 链接(文件快捷方式)
// r 读 w 写 x 执行
// 第一组 文件所有者拥有全部权限
// 第二组 与文件所有者同组用户 拥有 读写权限
// 第三组 不与文件所有者同组的用户 只有 读权限
try {
// 创建名为 readable.txt 的文件在 data/data/包名/files/..
FileOutputStream fos = openFileOutput("readable.txt", MODE_WORLD_READABLE);
fos.write("data".getBytes());
fos.close();
fos = openFileOutput("writeable.txt", MODE_WORLD_WRITEABLE);
fos.write("data".getBytes());
fos.close();
fos = openFileOutput("public.txt", MODE_WORLD_READABLE|MODE_WORLD_WRITEABLE);
fos.write("data".getBytes());
fos.close();
fos = openFileOutput("private.txt", MODE_PRIVATE);
fos.write("data".getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}