Hi there,
Where's the problem with my code?
I've already tested it by using different word patterns (aaa, a1a, 1a2, @sd, @23, @we34) and it seems to work.
The recommendation of my mentor "Be sure that your solution uses FileWriter" Am I not using it?
Thanks
package com.codegym.task.task19.task1923;
/*
Words with numbers
*/
import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Solution {
public static void main(String[] args) {
//args = new String[]{"C:\\Users\\Luis\\Desktop\\Prueba\\prueba1.txt", "C:\\Users\\Luis\\Desktop\\Prueba\\prueba2.txt"};
if(args.length==0){
return;
}
try(BufferedReader readerFile1 = new BufferedReader(new FileReader(args[0]))){
String REGEX = "\\d+";
Pattern pattern = Pattern.compile(REGEX);
while(readerFile1.ready()){
String[] line = readerFile1.readLine().split("\\s+");
for(String string : line) {
Matcher matcher = pattern.matcher(string);
if (matcher.find()){
try(FileWriter fileWriter = new FileWriter(args[1],true)) {
fileWriter.write(" ");
fileWriter.write(string);
}
}
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}