itslonua
11/21/2016 - 9:05 AM

Json Read from Raw Получить String из папки с ресурсами по Id

Json Read from Raw Получить String из папки с ресурсами по Id

public class DebugUtil {
    public static String loadData(Context context, int resId) {
        InputStream is = context.getResources().openRawResource(resId);
        Writer writer = new StringWriter();
        char[] buffer = new char[1024];
        try {
            Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            int n;
            while ((n = reader.read(buffer)) != -1) {
                writer.write(buffer, 0, n);
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeSilently(is);
        }

        return writer.toString();
    }
}