// TODO read text file private static String readTextFromFile(File file) { try { InputStream is = new FileInputStream(file); Writer writer = new StringWriter(); char[] buffer = new char[1024]; try { @SuppressWarnings("resource") Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } } finally { is.close(); } return writer.toString(); } catch (Exception e) { e.printStackTrace(); DNUtils.logError(e.getMessage()); return null; } }
// TODO write text file private static boolean writeTextIntoFile(String text, String path) { FileWriter writer; try { File file = new File(path); boolean isExists = file.exists(); writer = new FileWriter(path, false); writer.write(text); writer.flush(); writer.close(); file = new File(path); if (!isExists) { long size = STORE.getLong(KEY_SIZE, 0); size += file.length(); STORE.edit().putLong(KEY_SIZE, size).commit(); } } catch (IOException e) { e.printStackTrace(); DNUtils.logError(e.getMessage()); return false; } return true; }