Read and Write CSV File using Java
<p>I have a CSV log file and it contains many rows like this:</p>

<pre><code>2016-06-21 12:00:00,000 : helloworld: header1=2;header2=6;header=0
</code></pre>

<p>I want to write them to a new CSV file.</p>

<pre><code>public void readLogFile() throws Exception
{
    String currentLine = "";
    String nextLine = "";

    BufferedReader reader = new BufferedReader(new FileReader(file(false)));
    while ((currentLine = reader.readLine()) != null)
    {
        if (currentLine.contains("2016") == true)
        {
            nextLine = reader.readLine();
            if (nextLine.contains("helloworld") == true)
            {                   
                currentLine = currentLine.substring(0, 23);
                nextLine = nextLine.substring(22, nextLine.length());

                String nextBlock = replaceAll(nextLine);
                System.out.println(currentLine + " : helloworld: " + nextBlock);

                String[] data = nextBlock.split(";");
                for (int i = 0, max = data.length; i &lt; max; i++)
                {
                    String[] d = data[i].split("=");
                    map.put(d[0], d[1]);
                }
            }
        }
    }
    reader.close();
}
</code></pre>

<p>This is my method to write the content:</p>

<pre><code>public void writeContentToCsv() throws Exception
{
    FileWriter writer = new FileWriter(".../file_new.csv");
    for (Map.Entry&lt;String, String&gt; entry : map.entrySet())
    {
        writer.append(entry.getKey()).append(";").append(entry.getValue()).append(System.getProperty("line.separator"));
    }
    writer.close();
}
</code></pre>

<p>This is the output I want to have:</p>

<pre><code>header1; header2; header3
2;6;0
1;5;1
5;8;8
...
</code></pre>

<p>Currently, the CSV file looks like this (only showing one dataset):</p>

<pre><code>header1;4
header2;0
header3;0
</code></pre>

<p>Can anyone help me fix the code?</p>