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:
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");
}
}
Output should be
world
solid
(3245) (2334) (-234)
.
.
.
.
.
.
(457) (2) (2323)
instead, when i output to file, only the first coords appear:
(3245) (2334) (-234)