Test input:
file1 con4tains l5ines 6with 7words 8separated 9by spaces.
Write to file2 all the words that contain numbers, for example, a1 or abc3d. Separate the words with spaces.
output to 2nd file:
file1 con4tains l5ines 6with 7words 8separated 9by file2 a1 abc3d.
am I missing something here?package com.codegym.task.task19.task1923;
/*
Words with numbers
*/
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) throws IOException {
String f1 = args[0];
String f2 = args[1];
FileReader in = new FileReader(f1);
FileWriter out = new FileWriter(f2);
StringBuilder sb = new StringBuilder();
while (in.ready()){
sb.append((char)in.read());
}
String txt = sb.toString();
String[] words = txt.split(" ");
for(int i= 0; i<words.length; i++){
char[] temp = words[i].toCharArray();
for(int p = 0; p < temp.length; p++){
if (Character.isDigit(temp[p])){
out.write(words[i]+ " ");
break;
}
}
}
in.close();
out.close();
}
}