List of usage examples for android.content.res AssetManager open
public @NonNull InputStream open(@NonNull String fileName) throws IOException
From source file:Main.java
public static InputStream getInputStreamForName(Context context, String fileName) { AssetManager assetManager = context.getAssets(); InputStream inputStream = null; try {//from w w w . j ava 2 s.c o m inputStream = assetManager.open(fileName); } catch (IOException e) { e.printStackTrace(); } return inputStream; }
From source file:Main.java
public static final InputStream read(Context context, String path) { AssetManager assetManager = context.getAssets(); InputStream inputStream = null; try {// w w w . j a v a 2s. co m inputStream = assetManager.open(path); } catch (IOException e) { } return inputStream; }
From source file:Main.java
public static String readAssertsFile(Context context, String name) { try {//from w w w . j av a 2s . com AssetManager assetManager = context.getResources().getAssets(); InputStream inputStream = assetManager.open(name); String result = readInputStream(inputStream); inputStream.close(); return result; } catch (IOException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String readFromAssetsFile(Context context, String name) throws IOException { AssetManager am = context.getAssets(); BufferedReader reader = new BufferedReader(new InputStreamReader(am.open(name))); String line;/*from w ww . j a v a 2 s. c om*/ StringBuilder builder = new StringBuilder(); while ((line = reader.readLine()) != null) { builder.append(line); } reader.close(); return builder.toString(); }
From source file:Main.java
public static String getJsonAsString(String filename, Context context) throws IOException { AssetManager manager = context.getAssets(); StringBuilder buf = new StringBuilder(); InputStream json = manager.open(filename); BufferedReader in = new BufferedReader(new InputStreamReader(json, "UTF-8")); String str;//from ww w. jav a2 s . c om while ((str = in.readLine()) != null) { buf.append(str); } in.close(); return buf.toString(); }
From source file:Main.java
public static String readTextFromAssets(AssetManager assetManager, String fileName) { try {//www . ja v a 2 s.co m InputStreamReader inputReader = new InputStreamReader(assetManager.open(fileName)); BufferedReader bufReader = new BufferedReader(inputReader); String line; String Result = ""; while ((line = bufReader.readLine()) != null) Result += line; return Result; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String getAssertString(Context context, String filename) { AssetManager am = context.getAssets(); InputStream is = null;//from ww w . ja v a 2 s . c om try { is = am.open(filename); return new String(readInputStream(is)).trim(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:ch.ethz.coss.nervousnet.hub.ui.ShowcaseActivity.java
public static String parseJSONFile(String res, Context context) throws IOException { AssetManager manager = context.getAssets(); InputStream file = manager.open(res); byte[] formArray = new byte[file.available()]; file.read(formArray);/*from w ww .ja va 2 s. c om*/ file.close(); return new String(formArray); }
From source file:Main.java
private static void copyAssetFile(AssetManager assetManager, String assetFilePath, String destinationFilePath) throws IOException { InputStream in = assetManager.open(assetFilePath); OutputStream out = new FileOutputStream(destinationFilePath); // Transfer bytes from in to out byte[] buf = new byte[8192]; int len;/*from ww w . ja v a 2 s. c o m*/ while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:Main.java
public static Bitmap getBitmapFromAsset(Context context, String strName) { AssetManager assetManager = context.getAssets(); InputStream istr;//from ww w. j ava2s .c om Bitmap bitmap = null; try { istr = assetManager.open(strName); bitmap = BitmapFactory.decodeStream(istr); } catch (IOException e) { return null; } return bitmap; }