import java.io.BufferedReader;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader;import java.util.ArrayList; public class main { publicstatic void main(String[] args) throws IOException { ArrayList<String>lst = read("1.html");// read to arraylist if(lst.get(0).toLowerCase().startsWith("<html>") &&lst.get(lst.size() - 1).toLowerCase().endsWith("</html>"))//checking HTML for starts with <HTML> and ends with </HTML> { System.out.println(true);//An HTML file starts with <HTML> and ends with </HTML> (true) }else { System.out.println(false); } } /** * read file * * @param file * @return * @throws IOException */ publicstatic ArrayList<String> read(String file) throws IOException { ArrayList<String>lst = new ArrayList<String>(); Stringline = null; BufferedReaderbr = new BufferedReader(new InputStreamReader( newFileInputStream(file))); lst= new ArrayList<String>(); try{ while((line = br.readLine()) != null) { if(!(line = clearRow(line)).equals("")) { lst.add(line); } } }catch (IOException e) { e.printStackTrace(); } br.close(); returnlst; } /** * clear spaces and tabs * * @param row * @return */ publicstatic String clearRow(String row) { Stringres = row.replaceAll(" ", "");// clear all spaces res= res.replaceAll(" ","");// clear all tabs returnres; } }
Comments