Skip to main content

Posts

Showing posts from July, 2020

Java a program to convert text file to HTML

Write a program to convert  a text file into html file with questions and collapsible answers. I have a text file which has questions and answers. The file was extracted as a csv file from an sqlite database with ^^^ as a row separator and | as  a column separator. I read the file using nio  Files. readAllBytes() method.     Path filepath = Paths.get(filename); try { byte[] byteArray = Files.readAllBytes(filepath); String str = new String(byteArray); }catch(IOException e){ System.out.println(e.getMessage()); } As the method may throw IOException, I have wrapped it in try block.  The method reads the entire file and stores it in a bytearray which is conv   erted to string. Next to split the content into individual questions, I use string.split(regex) method.  This method splits the string into an array, breaking the string at the occurrence of regex. Unfor...