List of usage examples for android.content Context openFileInput
public abstract FileInputStream openFileInput(String name) throws FileNotFoundException;
From source file:Main.java
public static String getStringFromFile(final String filePath, final Context context) throws IOException { final FileInputStream in = context.openFileInput(filePath); final InputStreamReader inputStreamReader = new InputStreamReader(in); final BufferedReader bufferedReader = new BufferedReader(inputStreamReader); final StringBuilder sb = new StringBuilder(); String line;//w w w. j a va 2 s .c o m while ((line = bufferedReader.readLine()) != null) { sb.append(line); } return sb.toString(); }
From source file:Main.java
public static String GetCachedString(String filename, Context ctx) { try {// w w w . j a v a 2s . com InputStream inputStream = ctx.openFileInput(filename); if (inputStream != null) { InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String receiveString = ""; StringBuilder stringBuilder = new StringBuilder(); while ((receiveString = bufferedReader.readLine()) != null) { stringBuilder.append(receiveString); } inputStream.close(); return stringBuilder.toString(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static ObjectInputStream readObjectStream(Context context, String name) throws StreamCorruptedException, IOException { InputStream s = context.openFileInput(name); // FIXME - add buffering? return new ObjectInputStream(s); }
From source file:Main.java
static JSONObject load(Context ctxt, String fn) throws JSONException, IOException { FileInputStream is = ctxt.openFileInput(fn); InputStreamReader reader = new InputStreamReader(is); BufferedReader in = new BufferedReader(reader); StringBuilder buf = new StringBuilder(); String str;//from w w w . ja v a 2s .c o m while ((str = in.readLine()) != null) { buf.append(str); } in.close(); return (new JSONObject(buf.toString())); }
From source file:Main.java
public static String read(Context context, String fileName) { try {/* ww w .j a v a2 s . c o m*/ FileInputStream in = context.openFileInput(fileName); return readInStream(in); } catch (FileNotFoundException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
/** * Read details from a file//from w ww . java 2s . co m * @param full_file_name * @return */ public static String readFile(String full_file_name, Context context) { FileInputStream fis = null; try { fis = context.openFileInput(full_file_name); } catch (FileNotFoundException e) { e.printStackTrace(); } InputStreamReader isr = new InputStreamReader(fis); BufferedReader bufferedReader = new BufferedReader(isr); StringBuilder sb = new StringBuilder(); String line; try { while ((line = bufferedReader.readLine()) != null) { sb.append(line); } } catch (IOException e) { e.printStackTrace(); } // convert stringbuilder to string and split the whole file into multiple people return sb.toString(); }
From source file:Main.java
public static String read(Context context, String fileName) { try {//from w w w. j av a 2 s .c o m FileInputStream in = context.openFileInput(fileName); return readInStream(in); } catch (Exception e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String read(Context context, String fileName) { try {/*from w w w . j a va 2 s. c o m*/ FileInputStream in = context.openFileInput(fileName); return readInStream(in); } catch (Exception e) { // e.printStackTrace(); return ""; } }
From source file:Main.java
public static String readFromFileInput(Context context, String fileName) throws IOException { InputStream inputStream = context.openFileInput(fileName); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); int i;/*from w ww. j a v a2s . c o m*/ try { i = inputStream.read(); while (i != -1) { byteArrayOutputStream.write(i); i = inputStream.read(); } inputStream.close(); } catch (IOException e) { e.printStackTrace(); } return byteArrayOutputStream.toString(); }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T readSerializedObject(Context context, String fileName) throws FileNotFoundException, IOException, ClassNotFoundException { FileInputStream fis = context.openFileInput(fileName); ObjectInputStream in = new ObjectInputStream(fis); T out = (T) in.readObject();/*from w w w. jav a2 s. c om*/ in.close(); fis.close(); return out; }