1

I tried to create an object from FileInputStream() and pass the relative value of a file to its constructor,and save its data into the container , but it doesn't work properly and threw a Exception. I tried it in two different ways: The first one

 private void leerBD() {

    FileInputStream fin = null;
    ObjectInputStream ois = null;
    try {

        fin = new FileInputStream("C://Users/Jasmin/AndroidStudioProjects/FishCacher/app/src/main/res/raw/database.txt");
        ois = new ObjectInputStream(fin);
        bd = (HashMap<String, String>) ois.readObject();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        if (fin != null) {
            try {
                fin.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (ois != null) {
            try {
                ois.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}    

and the second one:

 private void leerBD() {
        FileInputStream fin = null;
        ObjectInputStream ois = null;
        try {

            fin = new FileInputStream("android.resource://(packageName)/raw/database.txt");
            ois = new ObjectInputStream(fin);
            bd = (HashMap<String, String>) ois.readObject();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (fin != null) {
                try {
                    fin.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (ois != null) {
                try {
                    ois.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

Neither of those are working.

0 Answers0