Creating directory in application package on internal storage

前端 未结 1 375
栀梦
栀梦 2020-12-14 22:55

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 ne

相关标签:
1条回答
  • 2020-12-14 23:34

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

    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 Example:

    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.
    
    0 讨论(0)
提交回复
热议问题