title: Write some part of a bson file into another bson file in java
body: <p>I have a bson file,(a.bson). I want to read this file and extract some part of it and then save these parts into another BSON file (b.bson).
  Currently, I can read my source file (a.bson) using org.bson.BSONEncoder and extract my favorite parts of it (e.g., key1 and key2 for each row of source fila). Now I want to save these data in another bson file (b.bson). In fact, I need to save this data in a bson file because this file has structure a I can easily check rows have contains spacial value or not. I write this code and </p>
  
  <pre><code>import org.bson.BSONEncoder;
  public static void createmyFile(File sourceFile) throws FileNotFoundException, IOException {
  
      InputStream inputStream = new BufferedInputStream(new FileInputStream(sourceFile));
      BSONDecoder decoder = new BasicBSONDecoder();                        
  
      try {
          while (inputStream.available() &gt; 0) {
              BSONObject bsonSingleRow = decoder.readObject(inputStream);  
            // --------------------------------------------------------------------- 
           // Write bsonSingleRow.get(key1) &amp; bsonSingleRow.get(key2) into new file
          // ---------------------------------------------------------------------
          }
  
      } catch (IOException e) {
          ...
      }        
  }
  </code></pre>
  
  <p>Please help me to complete above code.</p>