title: java (matcher.group()) - write to file
body: <p>I have code that finds coordinates between specific words.
  Now, output to console works perfect, but id like to output the matches found TO FILE
  My current code:</p>
  
  <pre><code>public class Filetostring {
  
  
  public static void main(String[] args) throws FileNotFoundException, IOException {
      String s = new Scanner(new File("input.txt")).useDelimiter("\\Z").next();
  //System.out.println(content);
  
  
      Pattern patt;
      patt = Pattern.compile("\\bworld\\b|\\bsolid\\b|.(-?\\d+\\s-?\\d+\\s-?\\d+\\)\\s\\     (-?\\d+\\s-?\\d+\\s-?\\d+\\)\\s\\(-?\\d+\\s-?\\d+\\s-?\\d+).");
      Matcher matcher = patt.matcher(s);
  while(matcher.find())
  //System.out.println(matcher.group());
  
  
  try (FileWriter file2 = new FileWriter("output.txt"); 
          BufferedWriter bf = new BufferedWriter(file2)) {
          bf.write(matcher.group());
  }
  
          System.out.println("Done");
  
  }
  
          }
  </code></pre>
  
  <p>Output should be </p>
  
  <p>world</p>
  
  <p>solid</p>
  
  <p>(3245) (2334) (-234)</p>
  
  <p>.</p>
  
  <p>.</p>
  
  <p>.</p>
  
  <p>.</p>
  
  <p>.</p>
  
  <p>.</p>
  
  <p>(457) (2) (2323)</p>
  
  <p>instead, when i output to file, only the first coords appear:</p>
  
  <p>(3245) (2334) (-234)</p>