title: Writing a CSV file in Java using OpenCSV
body: <p>[Edited] By editing my question, I have solved the problem. I just solved the problem by applying the following code to my method. I came to the decision to edit my old question. Because I have solved the problem.</p>
  <pre><code> ****if (!file.exists())
              theRows.clear();****
  
  @Repository
  public class DatabaseImpl implements Database {
  
      List&lt;String[]&gt; theRows = new ArrayList&lt;&gt;();
  
  
      @Override
      public int insert(String tableName, List&lt;String&gt; values) {
          File file = new File(tableName + &quot;.csv&quot;);
          if (!file.exists()) {
              prepareCsvFileAndInsertDataToCsvFile(values, file);
          } else {
              prepareCsvFileAndInsertDataToCsvFile(values, file);
          }
          return 0;
      }
  
      private void prepareCsvFileAndInsertDataToCsvFile(List&lt;String&gt; values, File file) {
          if (!file.exists())
              theRows.clear();
          try (CSVWriter writer = new CSVWriter(new FileWriter(file))) {
              String[] header = new String[]{&quot;id&quot;, &quot;name&quot;, &quot;surname&quot;, &quot;age&quot;, &quot;salary&quot;};
              theRows.add(values.toArray(String[]::new));//arasdiracam
              writer.writeNext(header);
              writer.writeAll(theRows, false);
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
  
      @Override
      public void update(String tableName, int rowId, List&lt;String&gt; values) {
  
      }
  
      @Override
      public List&lt;String&gt; select(String tableName, int rowId) {
          return null;
      }
  }
  </code></pre>