Back to project page hacktoolkit-android_lib.
The source code is released under:
MIT License
If you think the Android project hacktoolkit-android_lib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.hacktoolkit.android.utils; /*from w ww . j a v a 2 s .c o m*/ import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import android.app.Activity; import android.content.Context; // LOL, I wrote my own FileUtils, but there is an existing one. // Somehow I thought I was supposed to use android.os.FileUtils, which doesn't exist // http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html // http://commons.apache.org/proper/commons-io/download_io.cgi public class FileUtils { public static ArrayList<String> readLines(Activity activity, String filename) throws IOException { Context context = activity.getApplicationContext(); ArrayList<String> lines = new ArrayList<String>(); try { FileInputStream fin = context.openFileInput(filename); if (fin != null) { InputStreamReader inputStreamReader = new InputStreamReader(fin); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String line; while (( line = bufferedReader.readLine() ) != null) { lines.add(line); } fin.close(); } } catch (FileNotFoundException fnfe) { fnfe.printStackTrace(); } return lines; } public static int writeLines(Activity activity, String filename, ArrayList<String> lines) throws IOException { int linesWritten = 0; Context context = activity.getApplicationContext(); try { FileOutputStream fos = context.openFileOutput(filename, Context.MODE_PRIVATE); for (String line : lines) { // add terminal character so that it doesn't get written as one line fos.write((line + "\n").getBytes()); ++linesWritten; } fos.close(); } catch (FileNotFoundException fnfe) { fnfe.printStackTrace(); } return linesWritten; } }