back

// this program takes a text file and rewrites it in html format.
// save and compile this program, the file to be read, and the
// file to write to in the same folder

import java.io.*;
import java.util.*; //for scanner

public class CountWords
{
     public static void main(String[] args)
     throws FileNotFoundException
     {
         PrintStream output =
             new PrintStream(new File("overwrite.txt"));
         Scanner console = new Scanner(System.in);
         System.out.print("enter file name to convert to html: ");
         String read_file = console.next();
         Scanner input = new Scanner(new File(read_file));
         output.println("<body>\n\t<p>");
         while (input.hasNextLine())
         {
             String line = input.nextLine();
             processLine(line, output);
         }
         output.println("\t</p>\n</body>");
     }
    
     public static void processLine(String line, PrintStream output)
     {
         Scanner words = new Scanner(line);
         String text_1 = line;
         String text_2 = " \t";
         char[] the_array = line.toCharArray();
         char[] the_array_2 = text_2.toCharArray();
         int space_count = 0;
         for(int i = 0; i < the_array.length; i++)
         {
             if(the_array[i] == the_array_2[0])
             {
                 space_count += 1;
             }
             else if(the_array[i] == the_array_2[1])
             {
                 space_count += 4;
             }
             else
             {
                 i = 1000;
             }
         }
         //System.out.println(space_count);

         while(words.hasNext())
         {
             String word = words.next();
         }
         for(int i = 0; i < space_count; i++)
         {
             line = "&nbsp;" + line;
         }
         output.println(line + "<br/>");
     }
}