在应用程序包的内部存储创建目录 [英] Creating directory in application package on internal storage

查看:106
本文介绍了在应用程序包的内部存储创建目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能为Android应用程序创建的内部存储多个目录中存储有不同类型的文件?我需要这个功能,因为我需要删除我的应用程序中的一种,在一定的时间时刻的文件。

Is it possible for android application to create several directories in internal storage for storing there different kinds of files? I need this capability, because I'll need to delete a kind of files at definite time moment in my application.

当我尝试使用标准上下文方法 openFileOutput()并发送至其文件名以/符号我得到抛出:IllegalArgumentException

When I try to use standard Context method openFileOutput() and send to it filename with "/" symbol I get IllegalArgumentException.

请告诉我什么样的类和方法可以让我这样的功能?

Tell me please what classes and methods could allow me such functionality?

推荐答案

使用<一个href="http://developer.android.com/reference/android/content/Context.html#getDir%28java.lang.String,%20int%29">Context.getDir(String名,INT模式)的方法来创建或访问目录的内部存储。从文档报价:

Use Context.getDir(String name, int mode) method to create or access directories in internal storage. Quote from docs:

检索,创建如果需要的话,一个新的目录,其中,应用程序可以将其自己的自定义数据文件。您可以使用返回的文件对象创建和访问文件,此目录中。需要注意的是通过File对象创建的文件只能由你自己的应用程序访问;你可以只设置而不是单个文件的整个目录的方式。

Retrieve, creating if needed, a new directory in which the application can place its own custom data files. You can use the returned File object to create and access files in this directory. Note that files created through a File object will only be accessible by your own application; you can only set the mode of the entire directory, not of individual files.

UPD例如:

File mydir = context.getDir("mydir", Context.MODE_PRIVATE); //Creating an internal dir;
File fileWithinMyDir = new File(mydir, "myfile"); //Getting a file within the dir.
FileOutputStream out = new FileOutputStream(fileWithinMyDir); //Use the stream as usual to write into the file.

这篇关于在应用程序包的内部存储创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆