I am not sure whats wrong with the code - it seems to do what it should
1. I guess I have to use a loop for the FileReader for some reason (will try that)
It seems to return the tags for the example and template as required (guess not)
Does anyone have and idea whats wrong with it ?
Did I get the question wrong ?
Thanks everyone!
package com.codegym.task.task19.task1918;
/*
Introducing tags
*/
import java.io.*;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> tagcontent = new ArrayList<>();
File file = new File(reader.readLine());
reader.close();
char[] content = new char[(int) file.length()];
FileReader fileReader = new FileReader(file);
fileReader.read(content, 0,content.length);
fileReader.close();
String filecontent = new String(content);
Pattern startpattern = Pattern.compile("<"+args[0]+"\\b[^>]*>(.*?)</"+args[0]+">");
Matcher smatch = startpattern.matcher(filecontent);
int startpos = 0;
int endpos = 0;
while (!(smatch.hitEnd())) {
if (smatch.find()) {
tagcontent.add(smatch.group());
}
}
for (String s : tagcontent)
System.out.println(s);
}
}