繁体   English   中英

java.io.FileNotFoundException:/ storage / emulated / 0 /

[英]java.io.FileNotFoundException: /storage/emulated/0/

我正在尝试通过Android Studio中的应用创建一个.txt文件。 SDK版本10,我的模拟器是Galaxy S7(我不确定这是否很重要)。

我写了下面的课,它一直在给我文件没有异常错误。 我在Google上搜索了很多东西,并搜索了这个论坛,但没有一个在工作。

请帮忙。

我的课..

public static void StoreData(String input) throws IOException {
    File Root = Environment.getExternalStorageDirectory();
    Log.d("hello",Root.getAbsolutePath());
    File Dir = new File(Root.getAbsoluteFile() + "/testfolder");
    if (!Dir.exists()) {
        Log.d("hello","doesn't exists "+Root.getAbsolutePath());
        Dir.mkdir();
    }

    File file = new File(Dir, "Contacts_Google_Sheets.txt");
    FileOutputStream fileoutputstream = new FileOutputStream(file);
    fileoutputstream.write(input.getBytes());
    fileoutputstream.close();
    Log.d("hello", "writing complete");
}

它不断给出以下错误:

W/System.err: java.io.FileNotFoundException: /storage/emulated/0/testfolder/Contacts_Google_Sheets.txt (No such file or directory)
W/System.err:     at java.io.FileOutputStream.open(Native Method)
W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:169)
W/System.err:     at com.therock.app3_contact_list_googlesheet_public.FileOperations.StoreData(FileOperations.java:55)
W/System.err:     at com.therock.app3_contact_list_googlesheet_public.GetDataAsyncTask.doInBackground(GetDataAsyncTask.java:64)
W/System.err:     at com.therock.app3_contact_list_googlesheet_public.GetDataAsyncTask.doInBackground(GetDataAsyncTask.java:33)
W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:305)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
W/System.err:     at java.lang.Thread.run(Thread.java:761)
E/EGL_emulation: tid 3410: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x8fe424c0, error=EGL_BAD_MATCH

您必须从运行时检查权限。 如果您想立即测试代码,请转到设备的设置,应用,your_app,然后从中选择权限。 允许权限。 而且你很好走

确保您具有WRITE_EXTERNAL_STORAGE权限,包括在运行时请求它。

暂无
暂无

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

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