簡體   English   中英

android中的EBADF錯誤文件編號錯誤

[英]EBADF bad file number error in android

我正在嘗試將.properties文件寫入我的android項目的assets文件夾。 我似乎正在加載文件並修改它,但是當我去商店時它會向我吐出這個錯誤:

12-10 21:19:07.447: W/System.err(1781): java.io.IOException: write failed: EBADF (Bad file number)

我添加了寫入的權限,如:

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

我找到的Evrything說inputStream必須以某種方式關閉,但我怎么看?

文件名是config.properties,並且“Points = 0”是唯一的數據。

這是我的代碼(注意側滾動條)

public static void write(Context Activity){ // the activity passed in is "this" from the caller, who is an activity
    AssetManager am = Activity.getResources().getAssets();
    Properties pp = new Properties();
    InputStream isConfig = null;
    try {
        isConfig = am.open("config.properties",Context.MODE_PRIVATE);
        pp.load(isConfig);
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    pp.setProperty("Points", "1");//This key exists
    try {
        pp.store(Activity.getAssets().openFd("config.properties").createOutputStream(), null); //This is the problem
        isConfig.close();
    } catch (FileNotFoundException e) {
        System.err.println("file not found");
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("IO Exception");
        e.printStackTrace();
    }
}

您無法使用該應用程序寫入res / raw或assets文件夾。 您必須修改內容並將其存儲在外部存儲或內部文件系統或其他位置,但不能存儲在res / raw或assets文件夾中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM