private static void saveInCache(String trainNumber, String xml) { try { FileOutputStream fos = RozkladPKPApplication.getAppContext() .openFileOutput("route_" + trainNumber, Context.MODE_PRIVATE); fos.write(xml.getBytes()); fos.close(); } catch (Exception e) { e.printStackTrace(); } }
private static String getCached(String trainNumber) { FileInputStream fis; try { fis = RozkladPKPApplication.getAppContext().openFileInput("route_" + trainNumber); } catch (FileNotFoundException e) { return null; } ByteArrayOutputStream content = new ByteArrayOutputStream(); int readBytes = 0; try { while ((readBytes = fis.read(sBuffer)) != -1) content.write(sBuffer, 0, readBytes); } catch (IOException e) { return null; } return content.toString(); }