请查看以下代码
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();
}
这里我试图将数据写入内部存储器。这没有错误,显示数据已成功写入。
但是当我在手机中导航到内部SD时,我看不到它创建的任何文件夹或文件!我想我做错了,这是我第一次写入Android内部存储。
答案 0 :(得分:2)
File folder = new File(context.getFilesDir(),"/MyFolder/");
文件将在“/data/data/app.package/files / ...”中创建。但只有在设备已植根时才能看到它们
答案 1 :(得分:1)
您希望按here所述的方式访问getExternalStorageDirectory()
返回的路径。