简体   繁体   中英

Writing to existing file with help of assets manager in android

I am using the below code for reading my file and it is working fine, but now I want to add new text to that file. Please help me

private void loadingDictionary() {
// TODO Auto-generated method stub
    AssetManager mgr;

    try{
        mgr = getAssets();
        InputStream is = mgr.open("dictinary.txt");
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        StringBuilder  stringBuilder = new StringBuilder();
        String ls = ",";
        while(( line = br.readLine() ) != null){
        stringBuilder.append( line );
        stringBuilder.append( ls );
    }
    dictinaryLines = stringBuilder.toString();
    dictLinesArray = dictinaryLines.split(ls);
    }
    catch(IOException e1){
    }

}

I want to append the new text to the already existing data. Please help me.

As far as I know you can not write to the assets folder. You should copy the data from your assets folder to the private of your application or even to the external storage, depending on how confident your data is.

See How to write files to assets folder or raw folder in android?

You can't. How ever you can append a string called by res/values/strings.xml. If you were doing a theme I would have suggested to declare a string in res/values.strings.xml, and append it, then have whatever app you wanted to change whatever text to read from strngs.xml.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM