【问题标题】:FIleNotFoundException error was generated at runtime运行时生成 FIleNotFoundException 错误
【发布时间】:2013-03-23 13:02:02
【问题描述】:
private void readFileFromSDCard() {
        File directory = Environment.getExternalStorageDirectory();

        File file = new File(directory+"/HomeActivityLogs");
        //file.getParentFile().mkdirs();

        if (!file.exists()) {

            FileWriter gpxwriter;
            try {
                System.out.println(" IN TRY Error");
                file.createNewFile();
                gpxwriter = new FileWriter(file);

                System.out.println(" file writer Error");
            BufferedWriter out = new BufferedWriter(gpxwriter);
            out.write("http://192.168.1.126/msfaws2_4/Service.asmx");
            System.out.println(" in url Error");
        ///    out.write("http://192.168.1.250/msfaws2_4/Service.asmx");
            out.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                loginLog.appendLog("Exception in readFileFromSDCard() " + e.getMessage(),"MainActivity");
            }
        }

        BufferedReader reader = null;
        try {
            System.out.println("Error");
            reader = new BufferedReader(new FileReader(file));
            StringBuilder builder = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
            Constant.URL = builder.toString();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    loginLog.appendLog("Exception in readFileFromSDCard() " + e.getMessage(),"MainActivity");
                }
            }
        }
}

请帮我解决这个问题。它给出了一个带有文件名的错误 filenotfound 当数据临时存储然后从活动中检索时,它会从 Web 服务动态创建。

【问题讨论】:

  • 你在 mainfest 中添加了前置任务吗?

标签: android file android-file


【解决方案1】:

试试这个,给你添加这个权限manifest.xml

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

【讨论】:

  • 我提供互联网和Write_external_storage的权限
猜你喜欢
  • 2013-03-05
  • 1970-01-01
  • 2017-11-27
  • 1970-01-01
  • 2018-06-21
  • 2021-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多