package com.complet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.File;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;

public class HtmlFiles {

	private static ArrayList<String> lines = new ArrayList<String>();
	private static Path filepath;

	public static void checkPath(String path) {

		if (Files.exists(Paths.get(path))) {
			File theDir = new File(path.concat("\\HTML_Files"));
			theDir.mkdir();
			Mainclass.setPath(path.concat("\\HTML_Files"));
			Mainclass.setPath2(path.concat("\\HTML_Files"));

		} else {

			System.out.printf("%s", "Enter valid path : ");
			path = Mainclass.getInputpath().nextLine();
			checkPath(path);
		}
	}



	public static void createFile(String link, String path, int index) throws IOException {

		URL url = new URL(link);

		URLConnection connection = url.openConnection();

		BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));

		String inputLine;

		while ((inputLine = in.readLine()) != null) {

			lines.add(inputLine);
		}

		in.close();

		Path filepath = Paths.get(path);

			if (Files.exists(filepath)) {
				path = ((path.concat("\\")).concat(Integer.toString(index)).concat(".html"));
				filepath = Paths.get(path);
				Files.write(filepath, lines, Charset.forName("UTF-8"));
			} else {

				do {
					System.out.printf("%s", "Enter valid path : ");
					path = Mainclass.inputpath.nextLine();
					filepath = Paths.get(path);
				} while (!Files.exists(filepath));

				Mainclass.path = path;
				path = ((path.concat("\\")).concat(Integer.toString(index)).concat(".html"));
				filepath = Paths.get(path);
				Files.write(filepath, lines, Charset.forName("UTF-8"));
			}

			lines.removeAll(lines);
	}

	public static boolean deleteDirectory(File directory) {

		if (directory.exists()) {
			File[] files = directory.listFiles();
			if (null != files) {
				for (int i = 0; i < files.length; i++) {
					if (files[i].isDirectory()) {
						deleteDirectory(files[i]);
					} else {
						files[i].delete();
					}
				}
			}
		}
		return (directory.delete());
	}

}



@@ -853,18 +853,16 @@
 %09%09%7D%0A%09%7D%0A%0A
-%0A%0A
 %09public 
@@ -1237,81 +1237,16 @@
 );%0A%0A
-%09%09Path filepath = Paths.get(path);%0A%0A%09%09%09if (Files.exists(filepath)) %7B%0A%09%09%09%09
+        
 path
@@ -1311,34 +1311,32 @@
 ncat(%22.html%22));%0A
-%09%09
 %09%09filepath = Pat
@@ -1341,34 +1341,32 @@
 aths.get(path);%0A
-%09%09
 %09%09Files.write(fi
@@ -1411,408 +1411,25 @@
 ));%0A
-%09%09%09%7D else %7B%0A%0A%09%09%09%09do %7B%0A%09%09%09%09%09System.out.printf(%22%25s%22, %22Enter valid path : %22);%0A%09%09%09%09%09path = Mainclass.inputpath.nextLine();%0A%09%09%09%09%09filepath = Paths.get(path);%0A%09%09%09%09%7D while (!Files.exists(filepath));%0A%0A%09%09%09%09Mainclass.path = path;%0A%09%09%09%09path = ((path.concat(%22%5C%5C%22)).concat(Integer.toString(index)).concat(%22.html%22));%0A%09%09%09%09filepath = Paths.get(path);%0A%09%09%09%09Files.write(filepath, lines, Charset.forName(%22UTF-8%22));%0A%09%09%09%7D%0A%0A%09
+%0A%09%09// reset list%0A
 %09%09li

Delete the case if file exists