Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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
Java 文件存在,但在toast-it';它是空的_Java_Android - Fatal编程技术网

Java 文件存在,但在toast-it';它是空的

Java 文件存在,但在toast-it';它是空的,java,android,Java,Android,toast表示文件存在,但在此之后,读取响应为空。可能是什么错误 谢谢 fileName = "locations.txt"; File file = new File(Environment.getExternalStorageDirectory() .getAbsolutePath() + "/doma/" + fileName); String response = ""; if (file.exists()) { Toast.m

toast表示文件存在,但在此之后,读取响应为空。可能是什么错误

谢谢

fileName = "locations.txt";
File file = new File(Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/doma/" + fileName);

    String response = "";

    if (file.exists()) {
        Toast.makeText(this, fileName + " exists", Toast.LENGTH_SHORT).show();
        BufferedReader br;

        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "cp1252"));
            for (String line; (line = br.readLine()) != null; response += line + '\n') ;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Toast.makeText(this, "read:\n" + response, Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(this, "Sorry, " + fileName + " doesn't exist!!", Toast.LENGTH_LONG)
                .show();
    }

如果您引用的响应被设置为空
Toast.makeText(这是“read:\n”+response,Toast.LENGTH_SHORT).show()

您的吐司必须是文件,而不是文件名。。从哪里获得文件名的值

File file = new File(Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/doma/" + fileName);

    String response = "";

    if (file.exists()) {
        Toast.makeText(this, fileName + " exists", Toast.LENGTH_SHORT).show();
        BufferedReader br;

        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "cp1252"));
            for (String line; (line = br.readLine()) != null; response += line + '\n') ;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

Toast.makeText(this, "read:\n" + response, Toast.LENGTH_SHORT).show();
                .show();
    } else {
     Toast.makeText(this, "Sorry, " + file + " doesn't exist!!", Toast.LENGTH_LONG)
    }

如果您引用的响应被设置为空
Toast.makeText(这是“read:\n”+response,Toast.LENGTH_SHORT).show()

您的吐司必须是文件,而不是文件名。。从哪里获得文件名的值

File file = new File(Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/doma/" + fileName);

    String response = "";

    if (file.exists()) {
        Toast.makeText(this, fileName + " exists", Toast.LENGTH_SHORT).show();
        BufferedReader br;

        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "cp1252"));
            for (String line; (line = br.readLine()) != null; response += line + '\n') ;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

Toast.makeText(this, "read:\n" + response, Toast.LENGTH_SHORT).show();
                .show();
    } else {
     Toast.makeText(this, "Sorry, " + file + " doesn't exist!!", Toast.LENGTH_LONG)
    }

如果您引用的响应是空的
Toast.makeText(这是“read:\n”+response,Toast.LENGTH_SHORT).show()是的,变量响应为空,但不应为空。可能是什么问题?这应该可以工作…文件不是空的,是吗?您的try-catch块中是否提出了一个exeption?好的,问题已经解决了。缺少权限请求。谢谢你的帮助!如果您引用的响应是空的
Toast.makeText(这是“read:\n”+response,Toast.LENGTH_SHORT).show()是的,变量响应为空,但不应为空。可能是什么问题?这应该可以工作…文件不是空的,是吗?您的try-catch块中是否提出了一个exeption?好的,问题已经解决了。缺少权限请求。谢谢你的帮助!你是对的,我修复了它,现在仍然没有任何内容,请仔细检查这个
(Environment.getExternalStorageDirectory().getAbsolutePath()+“/doma/”+fileName)好的,问题已经解决了。缺少权限请求。谢谢你的帮助!你是对的,我修复了它,现在仍然没有任何内容,请仔细检查这个
(Environment.getExternalStorageDirectory().getAbsolutePath()+“/doma/”+fileName)好的,问题已经解决了。缺少权限请求。谢谢你的帮助!