This program retrieves user names and comments from a HTML f

This program retrieves user names and comments from a HTML file . It must be named \"project2.java\". It accepts input from a HTML file, called \"Apple.html\", which contains the comments of 4 users. It then retrieves user names and comments from \"Apple.html\" and writes appropriate output to another file, called \"Comments_out.txt\".

HTML file \"Apple.html\":

Comments

Teutonic Knight:IOS is so outdated it still needs all your apps organised from the top of the screen down.

DavidBCN:iOS10 proves Apple great advantage of hardware and software integration. Can Samsung provide the same ecosystem integration in multiple devices?

Liquid Crystal:Ever heard of Spotlight Search in iOS?

Dvillebill:Samsung has better fireworks

Sample \"Comments_out.text\":

Solution

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintWriter;
public class project2{
    public static void main(String[] args) {
        String output = new String();
        String contributor = new String();
        String comment = new String();
        String line = new String();
        try {
            BufferedReader br = new BufferedReader(new FileReader(\"Apple.html\"));
            StringBuilder sb = new StringBuilder();
            line = br.readLine();
            while (line != null) {
                sb.append(line);
                sb.append(System.lineSeparator());
                line = br.readLine();
                int ind = line.indexOf(\':\');
                if (ind>0){
                    contributor = line.substring(0, ind);
                    comment = line.substring(ind+1);
                    output += \"Contributor:\"+contributor+\"\ Comment:\"+comment+\"\ \ \";
                }
            }
            System.out.print(output);
            PrintWriter writer = new PrintWriter(\"Comments_out.txt\", \"UTF-8\");
            writer.print(output);
            writer.close();
        } catch(Exception e) {

        }

    }
}

This program retrieves user names and comments from a HTML file . It must be named \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site