title: java split string[] array to multiple files
body: <p>I'm having a problem figuring out how to split a string to multiple files. At the moment I should get two files both with JSON data. The code below writes to the first file but leaves the second empty. Any ideas why?</p>
  
  <pre><code>public void splitFile(List&lt;String&gt; results) throws IOException {
  
    int name = 0;
    for (int i=0; i&lt;results.size(); i ++) {
  
      write = new FileWriter("/home/tom/files/"+ name +".json");
      out = new BufferedWriter(write);
      out.write(results.get(i));
  
      if (results.get(i).startsWith("}")) {
        name++;
      }      
    } 
  }
  </code></pre>
  
  <p>Edit: it splits at line starting with <code>{</code> because that denotes the end of a JSON document.</p>