23 Ağustos 2017 Çarşamba

AssetManager Sınıfı

Giriş
Açıklaması şöyle
In res/ folder all xml files are precompiled, whereas in assets/ folder they are not.
Bu sınıf app/src/main/assets altındaki dosyaları okuyabilmemizi sağlar.

Constructor
Bu sınıf context nesnesi tarafından döndürülür. Şöyle yaparız
AssetManager am = context.getAssets();
Activity içinde şöyle yaparız.
Context context = getApplicationContext ();
AssetManager am = context.getAssets();
open metodu
Şöyle yaparız
InputStream is = am.open("words.txt");
Daha sonra bu stream ile dosyayı okumak için şöyle yaparız.
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;

while ((line = br.readLine()) != null) {
  ...
}

Hiç yorum yok:

Yorum Gönder