android - java.io.filenotfoundexception on trying to write on an existing file from different file -


i created file in internal memory in activity , want write on again on next activity getting error. in first activity:

string id_file = "tt_id"; string key_file = "tt_key"; fileoutputstream outputstream1; fileoutputstream outputstream2; try {    outputstream1 = openfileoutput(id_file, context.mode_private);    outputstream2 = openfileoutput(key_file, context.mode_private);    outputstream1.write(id.getbytes());    outputstream2.write(key.getbytes());    outputstream1.close();    outputstream2.close(); 

but in second activity:

fileoutputstream outputstream1; fileoutputstream outputstream2; string id="dfg"; string key="khdfks";     outputstream1 = openfileoutput("tt_id",context.mode_private);     outputstream2 = openfileoutput("tt_key", context.mode_private); outputstream1.write(id.getbytes()); outputstream2.write(key.getbytes()); outputstream1.close(); outputstream2.close(); 

i've started android app development, appreciated. thank in advance

i think need specify created file location before read/write. make sure file exists. else throw file not found exception. try this,

file file = new file(environment.getexternalstoragedirectory() + file.separator + "test.txt"); file.createnewfile(); if(file.exists()) {           outputstream outputstream1 = new fileoutputstream(file);          string id="dfg";     outputstream1.write(id.getbytes());     outputstream1.close(); }  

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -