2014-01-08 58 views
0

我開始學習將文件寫入SD卡。然而,我需要一些澄清,因爲我不明白爲什麼我在getAbsolutePath()(這是由Android工作室檢測到)的錯誤。getAbsolutePath() - 無法解析方法 - Android工作室

public class AndroidFileIO implements FileIO { 
    Context context; 
    AssetManager assets; 
    String externalStoragePath; 

public AndroidFileIO(Context context) { 
    this.context = context; 
    this.assets = context.getAssets(); 
    this.externalStoragePath = Environment.getExternalStorageState().getAbsolutePath() 
        + File.separator; 
} 

謝謝

+0

使用'getExternalStorageDirectory()''而不是getExternalStorageState()' – Raghunandan

回答

0

更改此

this.externalStoragePath = Environment.getExternalStorageState().getAbsolutePath() 
       + File.separator; 

this.externalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath() 
       + File.separator; 

更多信息@

http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

public static String getExternalStorageState() //返回類型爲字符串

Added in API level 1 
Returns the current state of the primary "external" storage device 

public static File getExternalStorageDirectory()

Added in API level 1 
Return the primary external storage directory 

,並期待在文檔爲File

http://developer.android.com/reference/java/io/File.html#getAbsolutePath()

public String getAbsolutePath()

Added in API level 1 
Returns the absolute path of this file. An absolute path is a path that starts at a root of the file system. On Android, there is only one root: /. 
+0

哈啊,謝謝 – user228229

+0

@ user228229因爲你是新來的StackOverflow看到這個http://meta.stackexchange.com/questions/5234/how-不接受-的應答工作。點擊答案旁邊的勾號標記答案已被接受,如果有幫助的話 – Raghunandan

相關問題