I am creating a Java Application to replace or a title to an HTML file. I have a folder of HTML files that I want to change the titles for and I don't want to manually do every HTML file. I want to read the HTML, find the title tag (i.e. <title>Some Title Here</title>), and replace it with a new title (i.e <title>Some New Title Here</title>) in each HTML file in the folder.
Can this be done using java? And how?
Keep getting IO Exceptions
for (int i = 0; i < listOfFiles.length; i++) {
    if (listOfFiles[i].isFile()) {
        File file = new File(listOfFiles[i].getName());
        BufferedReader in = new BufferedReader(new FileReader(file));
        String line = in.readLine();
        while (line != null) {
            if (line.contains(type)) {
                line = line.replaceAll(
                        "(<title>[A-Za-z0-9\\s]+</title>)",
                        "<title>New title</title>");
            }
            lines.add(line);
            line = in.readLine();
        }
        in.close();
        PrintWriter out = new PrintWriter(listOfFiles[i]);
        for (String l : lines)
            out.println(l);
        out.close();
        System.out.println("File " + listOfFiles[i].getName());
    } else if (listOfF`enter code here`iles[i].isDirectory()) {
        System.out.println("Directory " + listOfFiles[i].getName());
    }