InputStream in = getClass().getResourceAsStream("/assets/file.txt");
InputStream in_2 = getAssets().open("file.txt");
I would like to know the difference between these two methods. Will getAssets() perform better for android?
>Solution :
getAssets() is recommended for use in Android development whenever you’re looking to access files in the assets directory. That method is optimized for Android and ensures better performance and integration with the Android platform. As for getClass().getResourceAsStream in this case it looks like this is being used to access resources that are part of the class path but generally speaking the getResourceAsStream method is more common in Java applications. Here’s some resources https://docs.oracle.com/javase/8/docs/api/java/lang/ClassLoader.html#getResourceAsStream-java.lang.String-
https://developer.android.com/reference/android/content/res/AssetManager
I hope this helps!