Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android内部存储上创建文件?_Android - Fatal编程技术网

在Android内部存储上创建文件?

在Android内部存储上创建文件?,android,Android,我正试图在android的内部存储器中编写一个文本文件,并通过usb将其连接到PC进行浏览。现在,我使用了下面的代码,它对带有SD卡的旧设备运行良好 public void writeToFile(String stringToBeWritten) { final File path = Environment.getExternalStoragePublicDirectory ( Envi

我正试图在android的内部存储器中编写一个文本文件,并通过usb将其连接到PC进行浏览。现在,我使用了下面的代码,它对带有SD卡的旧设备运行良好

public void writeToFile(String stringToBeWritten)
{    
 final File path =
        Environment.getExternalStoragePublicDirectory
                (
                        Environment.DIRECTORY_DCIM + "/Target Folder/"
                );

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

final File file = new File(path, "MyFile.txt");

try
{
    file.createNewFile();
    FileOutputStream fOut = new FileOutputStream(file);
    OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
    myOutWriter.append(stringToBeWritten);
    System.out.println("Written Successfully");
    myOutWriter.close();

    fOut.flush();
    fOut.close();
}
catch (IOException e)
{
    Log.e("Exception", "File write failed: " + e.toString());
}
}
我上网已经有一段时间了,为了完成工作,我做了很多努力。所有解决方案都存在,用于在内部存储文件,但无法浏览


你知道如何在手机内部存储器上写文件吗?我非常感谢任何帮助/建议。谢谢。

你能告诉我你的手机版本吗?你的设备中有SD卡吗?我正在使用Oneplus One,没有SD卡@jiteshmohiteOnePlus一个api版本?它运行在Nougat 7.1(api级别25)上,您是否处理过存储的运行时权限?若并没有,那个么你们必须这样做。而且你们并没有sd卡,所以你们必须阅读如何在内部存储器中存储文件。如果你不能做到这些,请让我知道我会为你张贴答案