title: Android accessing asset file
body: <p>I want to access a text file located under assets from a class that would do some processing on that file and is invoked in my Activity. The code I am using is:</p>
  
  <pre><code>AssetManager assetManager = getAssets();
  InputStream instream = assetManager.open("file.txt");
  </code></pre>
  
  <p>this works fine if used in an Activity class but how to make it work in a plain java class?</p>
  
  <p>Edited</p>
  
  <p>JamesBlack - because if i pass the inputstream then the following code won't work</p>
  
  <pre><code>for (int i = 0; i &lt; gestureNumbers.size(); i++) {
     BufferedReader bf = new BufferedReader(new InputStreamReader(instream));
     // possible error here
     while ((line = bf.readLine()) != null) {  ...  }
  }
  </code></pre>
  
  <p>Even if the gestureNumbers.size() > 1 then the while loop is executed only once and then it equals null once it read the file once. </p>
  
  <p>When the following code works but I can't open the file in plain java class, it works in activity class and I don't want to have too much code in one class.</p>
  
  <pre><code>for (int i = 0; i &lt; gestureNumbers.size(); i++) {
     InputStream instream = assetManager.open("BSL_Word_POS.txt");
     BufferedReader bf = new BufferedReader(new InputStreamReader(instream));
     // possible error here
     while ((line = bf.readLine()) != null) { ... }
  }
  </code></pre>