2016-12-25 83 views
0

即時通訊設法打開4個txt文件,每個文件都有一個數組。每個數組都是包含這些維數的數組:12 x(每月的天數)。我需要在創建(啓動)我的應用程序時打開這些文件。數組中的值由逗號(,)分隔。該數組使用randoms值保存日曆。這裏是我得到了錯誤的代碼,但我不能解析:打開失敗:ENOENT(沒有這樣的文件或目錄)試圖打開一個文本文件

float[][] cargarDatos(float [][] matriz, String file){ 
    BufferedReader reader = null; 
    try { 
     (*)reader = new BufferedReader(new FileReader(Environment.getExternalStorageDirectory()+file)); 
     String line = ""; 
     int row = 0; 
     while((line = reader.readLine()) != null) 
     { 
      String[] cols = line.split(","); 
      int col = 0; 
      for(String c : cols){ 

        matriz[row][col] = Float.parseFloat(c); 

        col++; 


      } 
      row++; 
     } 
     reader.close(); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    return matriz; 
} 

而且,我已經在onCreate方法得到這個:

horasAno=cargarDatos(horasAno,"/anno2017Ordinaria.txt"); 

horasAno是4列,我需要一個與日期

錯誤,即時通訊越來越所有的時間來加載是:

W/System.err: java.io.FileNotFoundException: /storage/emulated/0/anno2017Ordinaria.txt: open failed: ENOENT (No such file or directory) 
W/System.err:  at libcore.io.IoBridge.open(IoBridge.java:418) 
W/System.err:  at java.io.FileInputStream.<init>(FileInputStream.java:78) 
W/System.err:  at java.io.FileInputStream.<init>(FileInputStream.java:105) 
W/System.err:  at java.io.FileReader.<init>(FileReader.java:66) 
W/System.err:  at com.example.oschertar.calendario.MainActivity.cargarDatos(MainActivity.java:265) 
W/System.err:  at com.example.oschertar.calendario.MainActivity.onCreate(MainActivity.java:104) 

有一個文件的Wi這個名字在這個目錄中。我在做什麼壞事?該生產線265標有(*)的行

+0

265行的郵政編碼 –

+0

您是否檢查過運行時權限? – Rahul

+0

該代碼發佈,是代碼中獲得(*)的通道(閱讀器=新BufferedReader ..) – oschertar

回答

0

我不能正確回答你的問題,但會建議檢查這些:

  • 你有閱讀你的清單中指定文件的權限?

  • 確保文件名和目錄是正確的。我看到很多人使用.toString()之後Environment.getExternalStorageDirectory()。我不知道爲什麼,並想知道它是否有幫助。

+0

我已經在我的清單中得到了這個: <使用權限android:name =」android.permission.READ_EXTERNAL_STORAGE「/> 我試過使用.toString()但即時獲取相同的錯誤。 – oschertar

相關問題