2013-03-23 71 views
0
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"); 
       } 
      } 
     } 
} 

请帮我解决这个问题。它给出了文件名 从Web服务动态地创建,当数据被储存临时,然后从活动中检索错误filenotfound。FIleNotFoundException错误在运行时产生

+2

没有ü添加在mainfest一个premission? – SelvaMariappan 2013-03-23 13:03:38

回答

0

试试这个,添加此权限在您manifest.xml

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

我提供互联网和Write_external_storage的permision也 – user2202251 2013-03-24 08:45:08

相关问题