默认本工程创建的文件本工程对其有读写权限。
我们可以通过context.openFileOutput("文件名", 模式);
我们可以创建私有, 共有, 只读, 只写文件, 默认的文私有文件。
如果别的Android工程访问本工程的文件的话就会受限制, android的内核是linux, 所以他的文件管理和linux中的文件时一样的。
创建文件代码:
/** * 创建各种文件 * @throws IOException * */ @SuppressLint({ "WorldWriteableFiles", "WorldReadableFiles" }) @SuppressWarnings("resource") private void createFile() throws IOException { Log.i(TAG, "开始创建文件"); FileOutputStream fos; //创建私有文件 fos = this.openFileOutput("private.txt", Context.MODE_PRIVATE); fos.write("private".getBytes()); fos.close(); //创建公有文件 fos = this.openFileOutput("public.txt", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); fos.write("public".getBytes()); fos.close(); //创建默认文件 File file = new File(this.getFilesDir(), "default.txt"); fos = new FileOutputStream(file); fos.write("default".getBytes()); fos.close(); //创建只读文件 fos = this.openFileOutput("readable.txt", Context.MODE_WORLD_READABLE); fos.write("readable".getBytes()); fos.close(); //创建只写文件 fos = this.openFileOutput("writeable.txt", Context.MODE_WORLD_WRITEABLE); fos.write("writeable".getBytes()); fos.close(); Toast.makeText(this, "文件创建成功", Toast.LENGTH_LONG).show(); Log.i(TAG, "创建文件完成"); }