Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //方法一
- File file = new File(context.getFilesDir(), filename);
- //方法二
- String filename = "myfile";
- String string = "Hello world!";
- FileOutputStream outputStream;
- try {
- outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
- outputStream.write(string.getBytes());
- outputStream.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- //方法三:cache file
- public File getTempFile(Context context, String url) {
- File file;
- try {
- String fileName = Uri.parse(url).getLastPathSegment();
- file = File.createTempFile(fileName, null, context.getCacheDir());
- } catch (IOException e) {
- // Error while creating file
- }
- return file;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement