lundi 18 mai 2015

Android write/read throwing FileNotFoundException

I'm new to Android and I'm using Android Studio 1.2.

So I'm using this code to write to file on one class:

 try {
            //registry is input by user when logging in..
                FileOutputStream fOut = openFileOutput(registry+ "d", MODE_APPEND);
                Toast.makeText(getApplicationContext(), "writing in " + registry+"d the value" + disciplina2, Toast.LENGTH_SHORT).show();
               //toast tells me it's writing properly on the correctly named file
                fOut.write(disciplina2.getBytes());
            } catch (FileNotFoundException e) {
                Toast.makeText(getApplicationContext(), "**not found**", Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                Toast.makeText(getApplicationContext(), "**io exception**", Toast.LENGTH_SHORT).show();
            }

Then on my other class that should access, read and fill a list I have:

try {
        InputStream inputstream = this.getAssets().open(registry + "d");
        BufferedReader buffer = new BufferedReader(new InputStreamReader(inputstream));

        while(buffer.readLine()!=null) {
            line = buffer.readLine();
            listaDisciplina.add(line);
            Toast.makeText(getApplicationContext(), "discipline " + line, Toast.LENGTH_SHORT).show();
        }
    }
    catch (FileNotFoundException e) {
        Toast.makeText(getApplicationContext(), "**not found** " + registry+"d", Toast.LENGTH_SHORT).show();
    } catch (IOException e) {
        Toast.makeText(getApplicationContext(), "**io excep D**", Toast.LENGTH_SHORT).show();
    }

It goes straight to FileNotFoundException even though the file names match and the writing definitely happened before the read.

Any thoughts?

Aucun commentaire:

Enregistrer un commentaire