How to input the data from multiple csv files using java
<p>I have some CSV file with the same column header.
I want to make them to one file.So I found something similar to me. Link is <a href="https://stackoverflow.com/questions/18020364/merge-csv-files-into-a-single-file-with-no-repeated-headers">Merge CSV files into a single file with no repeated headers</a>.
but I want to return the data as a String, but this code has no return.
I try to modify that. but I failed. 
I want to put the data from several csv into one variable.</p>

<pre><code>String[] headers = null;
String firstFile = "/path/to/firstFile.dat";
Scanner scanner = new Scanner(new File(firstFile));

if (scanner.hasNextLine())
    headers[] = scanner.nextLine().split(",");

scanner.close();

Iterator&lt;File&gt; iterFiles = listOfFilesToBeMerged.iterator();
BufferedWriter writer = new BufferedWriter(new FileWriter(firstFile, true));

while (iterFiles.hasNext()) {
  File nextFile = iterFiles.next();
  BufferedReader reader = new BufferedReader(new FileReader(nextFile));

  String line = null;
  String[] firstLine = null;
  if ((line = reader.readLine()) != null)
    firstLine = line.split(",");

  if (!Arrays.equals (headers, firstLine))
    throw new FileMergeException("Header mis-match between CSV files: '" +
              firstFile + "' and '" + nextFile.getAbsolutePath());

  while ((line = reader.readLine()) != null) {
    writer.write(line);
    writer.newLine();
  }

  reader.close();
}
writer.close();
</code></pre>