文件保存在内部存储器中的位置

时间:2015-11-26 12:36:27

标签: android internal-storage

我正在开发针对华硕Nexus 7,我没有SD卡,我正在尝试在内部存储中创建一个文件,如下面的代码所示。 当我运行应用程序时,没有创建文件,因为我不知道文件的保存位置..

如下面的日志输出所示,文件“TEST.txt”在/ storage / emulated / 0 / CAN_BUS下创建

但我没有/ storage /..

文件保存在哪里?

注意:发布的代码来自Android开发者网站

日志输出

 +++++ isExternalStorageMounted() +++++
11-26 13:31:11.264 17601-17601/com.example.com.bt_11 D/IOCtrl: isExternalStorageMounted(): -> media state: mounted
11-26 13:31:11.265 17601-17601/com.example.com.bt_11 D/IOCtrl: dir: /storage/emulated/0/CAN_BUS already exists
11-26 13:31:11.266 17601-17601/com.example.com.bt_11 D/IOCtrl: file: TEST.txt already exists

private final static String DIR_NAME = "CAN_BUS";
private final static String ROOT_DIR = Environment.getExternalStorageDirectory().toString();

if (IOCtrl.isExternalStorageMounted()) {

        File dir = new File(IOCtrl.ROOT_DIR + File.separator + IOCtrl.DIR_NAME);
        boolean dirCreated = dir.mkdirs();

        if (dirCreated) {
            Log.d(TAG, "dir: " + dir.getAbsolutePath() + " created");
        } else {
            Log.d(TAG, "dir: " + dir.getAbsolutePath() + " already exists");
        }

        File file = new File(dir, fileName);
        boolean fileExists = file.exists();

        if (fileExists) {
            Log.d(TAG, "file: " + fileName + " already exists");
        } else {
            Log.d(TAG, "file: " + fileName + " will be created");
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
                Log.e(TAG, CSubTag.subBullet("createFile", "Error creating file: " + e.getMessage()));
                return null;
            }
        }

        return file;
    } else {
        Log.e(TAG, CSubTag.msg("createFile", "media storage is not available"));
        return null;
    }

1 个答案:

答案 0 :(得分:0)

您的文件已保存在设备的内部存储空间中。您可以在Eclipse或Android Studio中看到使用DDMS工具。

有用的链接:http://www.codeproject.com/Articles/825304/Accessing-internal-data-on-Android-device