Code example for FileInputStream

Methods: close, read

0
            String data = "";
             
            try { 
                // read file into a string 
                byte[] buffer = new byte[(int) SETTINGS_FILE.length()];
                f = new FileInputStream(SETTINGS_FILE);
                f.read(buffer);
                data = new String(buffer);
            } catch(Exception e) {
                Log.e(TAG, "Error reading settings file", e);
            } finally { 
                // ensure the stream is closed 
                if(f != null) try { f.close(); } catch(Exception ignored) { }
            } 
             
            try { 
                // parse as JSON 
                JSONObject json = new JSONObject(data);
                 
                if(json.has(RESTART_ADB_KEY)) {
                    mRestartAdb = json.optBoolean(RESTART_ADB_KEY, true);