CSV to HTML Converter I have written a little program that converts a CSV-File to an HTML-Table. It works for my purposes. But are there parts in my code that can be written more clean? Can you improve maybe the performance? Are there maybe any bugs? I searched for bugs and fortunately I did not find some.
Postscript
Maybe I should have provided some background information: I am working on a database documentation that I am writing as an HTML document, because I dont like Word-documents. However, creating a tabular description of the columns with dozens of tags is painful. That is why I wrote this script: Now I only have to export the table information as CSV and can convert it directly without having to enter many tags myself. This is why there are no HTML and body tags: The tables created should not be separate HTML documents, but parts of a single, large HTML document.
CsvToHtmlTable.java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileWriter;
import java.util.List;
import java.util.ArrayList;

public class CsvToHtmlTable {
    public static void main(String[] args) {
        // print info and show user how to call the program if needed
        System.out.println(&quot;This program is tested only for UTF-8 files.&quot;);
        if (args[0].equalsIgnoreCase(&quot;help&quot;) || args[0].equalsIgnoreCase(&quot;-help&quot;) || args.length != 2) {
            System.out.println(&quot;java CsvToHtmlTable &lt;input file&gt; &lt;output file&gt;&quot;);
            System.out.println(&quot;Example: java CsvToHtmlTable nice.csv nice.html&quot;);
            System.exit(0);
        }
        
        String csvFile = args[0];
        String outputFile = args[1];
        
        // read lines of csv to a string array list
        List&lt;String&gt; lines = new ArrayList&lt;String&gt;();
        try (BufferedReader reader = new BufferedReader(new FileReader(csvFile))) {
            String currentLine;
            while ((currentLine = reader.readLine()) != null) {
                lines.add(currentLine);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        
        //embrace &lt;td&gt; and &lt;tr&gt; for lines and columns
        for (int i = 0; i &lt; lines.size(); i++) {
            lines.set(i, &quot;&lt;tr&gt;&lt;td&gt;&quot; + lines.get(i) + &quot;&lt;/td&gt;&lt;/tr&gt;&quot;);
            lines.set(i, lines.get(i).replaceAll(&quot;,&quot;, &quot;&lt;/td&gt;&lt;td&gt;&quot;));
        }
        
        // embrace &lt;table&gt; and &lt;/table&gt;
        lines.set(0, &quot;&lt;table border&gt;&quot; + lines.get(0));
        lines.set(lines.size() - 1, lines.get(lines.size() - 1) + &quot;&lt;/table&gt;&quot;); 
        
        // output result
        try (FileWriter writer = new FileWriter(outputFile)) {
            for (String line : lines) {
                writer.write(line + &quot;\n&quot;);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

How to call the program:
java CsvToHtmlTable ExampleInput.csv ExampleOutput.html

ExampleInput.csv
Name,Vorname,Alter
Ulbrecht,Klaus Dieter,12
Meier,Bertha,102

ExampleOutput.html


&lt;table border&gt;&lt;tr&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;Vorname&lt;/td&gt;&lt;td&gt;Alter&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Ulbrecht&lt;/td&gt;&lt;td&gt;Klaus Dieter&lt;/td&gt;&lt;td&gt;12&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Meier&lt;/td&gt;&lt;td&gt;Bertha&lt;/td&gt;&lt;td&gt;102&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
CSVReader
Reading a CSV file can be a complex task.  While many CSV files are just comma-separated-values, if a value contains a comma, it would be surrounded by double quotes, and if the value contains double quotes, the double quotes themselves are doubled.
To handle these more that just a basic CSV files, you really should use a CSV library, such as OpenCSV (com.opencsv:opencsv:5.0) or Apache Commons CSV (org.apache.commons:commons-csv:1.7).
HTML
Valid HTML
Your code essentially just writes &lt;table&gt;...table data...&lt;/table&gt;.  This isn't proper HTML.  You're missing &lt;html&gt;...&lt;/html&gt; tags around the entire document, and &lt;body&gt;...&lt;/body&gt; around the content.  You should probably also have a &lt;head&gt;...&lt;/head&gt;, perhaps with a nice &lt;title&gt;...&lt;/title&gt;.
Escaping
If your CSV data contains any special characters, like &lt;, &gt;, and &amp;, you really must escape them in the generated HTML table.
Table Headings
It looks like the first line of your table contains headings, not data.  The first table row should probably be formatted with &lt;th&gt;...&lt;/th&gt; tags instead of &lt;td&gt;...&lt;/td&gt; tags.
Line by Line processing
You are reading the entire CSV file into memory, and only when it has been loaded in its entirety are you writing it back out as HTML.  This is very memory intensive, especially if the CSV file is huge!
Instead, you could:

open the CSV
open the HTML file
write the HTML prolog
for each line read from CSV file:

format and write line to HTML file


write HTML epilog

Untested, coding from the hip, without handling quoting in CSV or escaping any HTML entities in output:
        try (BufferedReader reader = new BufferedReader(new FileReader(csvFile));
             FileWriter writer = new FileWriter(outputFile)) {

            writer.write(&quot;&lt;html&gt;&lt;body&gt;&lt;table border&gt;\n&quot;);

            String currentLine;
            while ((currentLine = reader.readLine()) != null) {
                writer.write(&quot;&lt;tr&gt;&quot;);

                for(String field: currentLine.split(&quot;,&quot;))
                    writer.write(&quot;&lt;td&gt;&quot; + field + &quot;&lt;/td&gt;&quot;);

                writer.write(&quot;&lt;/tr&gt;\n&quot;);
            }

            writer.write(&quot;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;\n&quot;);

        } catch (IOException e) {
            e.printStackTrace();
        }

XML &amp; XSLT
You may want to consider creating a CSV to XML translator.
Your XML output might look like:
&lt;data input-file='ExampleInput.csv'&gt;
  &lt;person&gt;
    &lt;Name&gt;Ulbrecht&lt;/Name&gt;
    &lt;Vorname&gt;Klaus Dieter&lt;/Vorname&gt;
    &lt;Alter&gt;12&lt;/Alter&gt;
  &lt;/person&gt;
  &lt;person&gt;
    &lt;Name&gt;Meier&lt;/Name&gt;
    &lt;Vorname&gt;Bertha&lt;/Vorname&gt;
    &lt;Alter&gt;102&lt;/Alter&gt;
  &lt;/person&gt;
&lt;/data&gt;

And then you could use an XSLT Stylesheet to translate the XML to HTML, possibly in a browser without ever writing the HTML to a file.