简体   繁体   English

android中的EBADF错误文件编号错误

[英]EBADF bad file number error in android

I am attempting to write a .properties file to the assets folder of my android project. 我正在尝试将.properties文件写入我的android项目的assets文件夹。 I seem to be loading the file and modifying it fine, but when I go to store it spits this error at me: 我似乎正在加载文件并修改它,但是当我去商店时它会向我吐出这个错误:

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

I have added the permissions to write like: 我添加了写入的权限,如:

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

Evrything I find says the inputStream must somehow be closed, but I dont see how? 我找到的Evrything说inputStream必须以某种方式关闭,但我怎么看?

File name is config.properties and has "Points=0" as the only data. 文件名是config.properties,并且“Points = 0”是唯一的数据。

Here is my code(note side scrollbar) 这是我的代码(注意侧滚动条)

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();
    }
}

You cannot write to your res/raw or assets folder using the application. 您无法使用该应用程序写入res / raw或assets文件夹。 You will have to modify the contents and store it in external storage or internal file system or somewhere else but not in res/raw or assets folder. 您必须修改内容并将其存储在外部存储或内部文件系统或其他位置,但不能存储在res / raw或assets文件夹中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IOException: write failed: EBADF (Bad file number) - IOException: write failed: EBADF (Bad file number) Android Java IOException从文件描述符/输入流中读取失败的EBADF(错误文件编号) - Android Java IOException read failed EBADF (Bad File Number) From File descriptor/Input Stream Android java.io.IOException:写入失败:EBADF(错误的文件号) - Android java.io.IOException: write failed: EBADF (Bad file number) SocketException:sendto失败:EBADF(错误的文件描述符) - SocketException: sendto failed: EBADF (Bad file descriptor) RandomAccessFile.write: EBADF(坏文件描述符) - RandomAccessFile.write: EBADF (Bad file descriptor) java.net.SocketException:recvfrom失败:EBADF(错误的文件描述符)Android - java.net.SocketException: recvfrom failed: EBADF (Bad file descriptor) Android 如何知道是否写入流是否会导致java.io.IOException:写入失败:EBADF(错误的文件号) - How to know whether writing to stream would result in java.io.IOException: write failed: EBADF (Bad file number) java.io.IOException:读取失败:EBADF(错误的文件描述符) - java.io.IOException: read failed: EBADF (Bad file descriptor) JRuby嵌入问题:放入失败,出现RaiseException:(Errno :: EBADF)错误的文件描述符 - JRuby Embedding prob: Puts appears to fails with RaiseException: (Errno::EBADF) Bad file descriptor JRuby-方法“ eval”的第二次调用给出(Errno :: EBADF)错误的文件描述符 - JRuby - second call of method “eval” gives (Errno::EBADF) Bad file descriptor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM