/** * @param name * @return * @throws FileNotFoundException * @see android.content.ContextWrapper#openFileInput(java.lang.String) */ public FileInputStream openFileInput(String name) throws FileNotFoundException { return mActivity.openFileInput(name); }
/** * Loads a file from internal storage * @param fileName The fileName of the file. * @param activity The current activity. * @return The loaded file. */ private static String load(String fileName, Activity activity) { String result = ""; try { FileInputStream inputStream = activity.openFileInput(fileName); byte[] input = new byte[inputStream.available()]; while (input.length !=0 && inputStream.read(input) != -1) { result += new String(input); } inputStream.close(); } catch (FileNotFoundException e) { Log.e(TAG, "No old file to load with key '" + fileName + "'"); return null; } catch (IOException e) { Log.e(TAG, e.toString()); return null; } Log.e(TAG, "loaded file from external storage: " + fileName); return result; }
public static ShortcutSerializableData loadSerializedShortcutData(){ ObjectInputStream inputStram = null; try{ inputStram = new ObjectInputStream(MainActivity.activity.openFileInput("shortcutdata")); Object obj = inputStram.readObject(); if (obj instanceof ShortcutSerializableData){ return (ShortcutSerializableData)obj; }else return null; }catch (EOFException e){ e.printStackTrace(); }catch (ClassNotFoundException e){ e.printStackTrace(); }catch (FileNotFoundException e){ e.printStackTrace(); }catch (IOException e){ e.printStackTrace(); }finally{ try{ if (inputStram!=null){ inputStram.close(); } }catch (IOException e){ e.printStackTrace(); } } return null; }
inputStram = new ObjectInputStream(MainActivity.activity.openFileInput("data")); Object obj = inputStram.readObject();
public void loadList() { list.clear(); try { FileInputStream inputStream = owner.openFileInput(FILE_NAME); BufferedReader input = new BufferedReader(new InputStreamReader(inputStream)); while (true) { String line = input.readLine(); if (line == null) break; Info info = new Info(); int where = findSpace(line, 0); info.id = Integer.parseInt(line.substring(0, where)); int start = where + 1; where = findSpace(line, where + 1); info.sideLength = Double.parseDouble(line.substring(start, where)); start = where + 1; where = findSpace(line, where + 1); info.units = UnitsDistance.valueOf(line.substring(start, where)); info.name = line.substring(where + 1, line.length()); list.add(info); } inputStream.close(); } catch( FileNotFoundException ignore) { Log.d(TAG,"Fiducial index file not found"); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Read the wishlist from a file and return it as an ArrayList<MtgCard> * * @param activity A context to open the file and pop toasts with * @param loadFullData true to load all card data from the database, false to just read the file * @return The wishlist in ArrayList form */ public static ArrayList<MtgCard> ReadWishlist(Activity activity, boolean loadFullData) throws FamiliarDbException { ArrayList<MtgCard> lWishlist = new ArrayList<>(); int orderAddedIdx = 0; try { String line; try (BufferedReader br = new BufferedReader(new InputStreamReader(activity.openFileInput(WISHLIST_NAME)))) { /* Read each line as a card, and add them to the ArrayList */ while ((line = br.readLine()) != null) { MtgCard card = MtgCard.fromWishlistString(line, false, activity); card.setIndex(orderAddedIdx++); lWishlist.add(card); } } } catch (NumberFormatException e) { SnackbarWrapper.makeAndShowText(activity, e.getLocalizedMessage(), SnackbarWrapper.LENGTH_LONG); } catch (IOException e) { /* Catches file not found exception when wishlist doesn't exist */ } if (loadFullData && !lWishlist.isEmpty()) { MtgCard.initCardListFromDb(activity, lWishlist); } return lWishlist; }
try (BufferedReader br = new BufferedReader(new InputStreamReader(activity.openFileInput(deckName)))) { boolean isSideboard;
stream = activity.openFileInput(filename); if (stream != null) { return stream;