简体   繁体   English

无法写入内部存储

[英]Unable to write to the Internal Storage

Please have a look at the following code 请看下面的代码

File folder = new File("/Main Note/Sub Notes/"+dateStr+"/");
File file = new File(folder+name.getText().toString()+".txt");
    try
    {

        if(!folder.exists())
        {
            folder.mkdirs();
        }

        FileOutputStream outputStream =  openFileOutput(file.getName(),Context.MODE_WORLD_WRITEABLE);
        outputStream.write(spokenText.getBytes());
        outputStream.flush();
        outputStream.close();

        Toast.makeText(VoiceNotes.this, "Data Successfully written to: "+file.getAbsolutePath(), Toast.LENGTH_LONG).show();
    }
    catch(IOException io)
    {
        Toast.makeText(VoiceNotes.this, "Error in Writing to SD", Toast.LENGTH_LONG).show();
    }

Here I am trying to write data to the internal memory. 在这里,我试图将数据写入内部存储器。 This has no errors, displays the data has been written successfully. 这没有错误,显示数据已成功写入。

But when I navigate to the Internal SD in phone, I don't see any folder or file it created! 但是当我导航到手机中的内部SD时,看不到它创建的任何文件夹或文件! I guess I have done something wrong, this is the first time I am writing to the internal storage in Android. 我想我做错了什么,这是我第一次写入Android的内部存储。

File folder = new File(context.getFilesDir(),"/MyFolder/");

files will be created in "/data/data/app.package/files/...". 文件将在“ /data/data/app.package/files / ...”中创建。 But you can see them only if device was rooted 但是只有在设备已植根的情况下,您才能看到它们

要访问返回的路径getExternalStorageDirectory()所描述的在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM