@Test public void testLoadFileContent() throws Exception { File folder = new File("build/intermediates/bundles/debug"); if(!folder.exists()){ folder = new File("build/intermediates/bundles/release"); } File file = new File(folder,"assets/test"); System.out.println(file.getAbsolutePath()); if(!file.exists()){ file.createNewFile(); } WXFileUtils.loadAsset("test", RuntimeEnvironment.application); }
public static String loadAsset(String path, Context context) { if (context == null || TextUtils.isEmpty(path)) { return null; } InputStream inputStream = null; BufferedReader bufferedReader = null; try { inputStream = context.getAssets().open(path); StringBuilder builder = new StringBuilder(inputStream.available() + 10); bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); char[] data = new char[4096]; int len = -1; while ((len = bufferedReader.read(data)) > 0) { builder.append(data, 0, len); } return builder.toString(); } catch (IOException e) { e.printStackTrace(); WXLogUtils.e("", e); } finally { try { if (bufferedReader != null) bufferedReader.close(); } catch (IOException e) { WXLogUtils.e("WXFileUtils loadAsset: ", e); } try { if (inputStream != null) inputStream.close(); } catch (IOException e) { WXLogUtils.e("WXFileUtils loadAsset: ", e); } } return ""; }
WXFileUtils { public static String loadAsset(String path, Context context) { if (context == null || TextUtils.isEmpty(path)) { return null; } InputStream inputStream = null; BufferedReader bufferedReader = null; try { inputStream = context.getAssets().open(path); StringBuilder builder = new StringBuilder(inputStream.available() + 10); bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); char[] data = new char[4096]; int len = -1; while ((len = bufferedReader.read(data)) > 0) { builder.append(data, 0, len); } return builder.toString(); } catch (IOException e) { e.printStackTrace(); WXLogUtils.e("", e); } finally { try { if (bufferedReader != null) bufferedReader.close(); } catch (IOException e) { WXLogUtils.e("WXFileUtils loadAsset: ", e); } try { if (inputStream != null) inputStream.close(); } catch (IOException e) { WXLogUtils.e("WXFileUtils loadAsset: ", e); } } return ""; } }
WXFileUtils { public static String loadAsset(String path, Context context) { if (context == null || TextUtils.isEmpty(path)) { return null; } InputStream inputStream = null; BufferedReader bufferedReader = null; try { inputStream = context.getAssets().open(path); StringBuilder builder = new StringBuilder(inputStream.available() + 10); bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); char[] data = new char[4096]; int len = -1; while ((len = bufferedReader.read(data)) > 0) { builder.append(data, 0, len); } return builder.toString(); } catch (IOException e) { e.printStackTrace(); WXLogUtils.e("", e); } finally { try { if (bufferedReader != null) bufferedReader.close(); } catch (IOException e) { WXLogUtils.e("WXFileUtils loadAsset: ", e); } try { if (inputStream != null) inputStream.close(); } catch (IOException e) { WXLogUtils.e("WXFileUtils loadAsset: ", e); } } return ""; }  }
WXFileUtils { public static String loadAsset(String path, Context context) { if (context == null || TextUtils.isEmpty(path)) { return null; } InputStream inputStream = null; BufferedReader bufferedReader = null; try { inputStream = context.getAssets().open(path); StringBuilder builder = new StringBuilder(inputStream.available() + 10); bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); char[] data = new char[4096]; int len = -1; while ((len = bufferedReader.read(data)) > 0) { builder.append(data, 0, len); } return builder.toString(); } catch (IOException e) { e.printStackTrace(); WXLogUtils.e("", e); } finally { try { if (bufferedReader != null) bufferedReader.close(); } catch (IOException e) { WXLogUtils.e("WXFileUtils loadAsset: ", e); } try { if (inputStream != null) inputStream.close(); } catch (IOException e) { WXLogUtils.e("WXFileUtils loadAsset: ", e); } } return ""; }  static String loadAsset(String path, Context context); static boolean saveFile(String path, byte[] content, Context context); }
WXFileUtils { public static String loadAsset(String path, Context context) { if (context == null || TextUtils.isEmpty(path)) { return null; } InputStream inputStream = null; BufferedReader bufferedReader = null; try { inputStream = context.getAssets().open(path); StringBuilder builder = new StringBuilder(inputStream.available() + 10); bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); char[] data = new char[4096]; int len = -1; while ((len = bufferedReader.read(data)) > 0) { builder.append(data, 0, len); } return builder.toString(); } catch (IOException e) { e.printStackTrace(); WXLogUtils.e("", e); } finally { try { if (bufferedReader != null) bufferedReader.close(); } catch (IOException e) { WXLogUtils.e("WXFileUtils loadAsset: ", e); } try { if (inputStream != null) inputStream.close(); } catch (IOException e) { WXLogUtils.e("WXFileUtils loadAsset: ", e); } } return ""; }  static String loadAsset(String path, Context context); static boolean saveFile(String path, byte[] content, Context context);  }