import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class main {
public
static 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
*/
public
static ArrayList<String> read(String file) throws IOException {
ArrayList<String>
lst = new ArrayList<String>();
String
line = null;
BufferedReader
br = new BufferedReader(new InputStreamReader(
new
FileInputStream(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();
return
lst;
}
/**
* clear spaces and tabs
*
* @param row
* @return
*/
public
static String clearRow(String row) {
String
res = row.replaceAll(" ", "");// clear all spaces
res
= res.replaceAll(" ",
"");// clear all tabs
return
res;
}
}
Comments
Leave a comment