public long mergeSortedFiles(List<File> files, File outputfile,
			String tableTitle, final Comparator<TxtTable.Row> cmp,
			String delimiter, char escape, boolean saveKey) throws IOException
	{
		PriorityQueue<TxtTable> pq = new PriorityQueue<TxtTable>(11,
				new Comparator<TxtTable>() {
					public int compare(TxtTable i, TxtTable j) {
						return cmp.compare(i.peek(), j.peek());
					}
				});
		
		if (delimiter == null) delimiter = TxtTable.DEFAULT_DELIMITER;
		
		for (File f : files)
		{
			TxtTable table = new TxtTable(f.getAbsolutePath(),
					new FirstRowKeyGenerator(), null, true, delimiter, escape);

			table.reload();
			pq.add(table);
		}

		BufferedWriter fbw = new BufferedWriter(new OutputStreamWriter(
				new FileOutputStream(outputfile)));

		if (saveKey) fbw.write("ID_ID" + delimiter);

		fbw.write(tableTitle);
		fbw.newLine();

		int rowcounter = 0;

		try 
		{
			while (pq.size() > 0) 
			{
				TxtTable table = pq.poll();
				TxtTable.Row r = table.pop();

				if (saveKey)
					fbw.write(r.getContent());
				else
					fbw.write(removeFirstElement(r.getContent(), delimiter));
				
				fbw.newLine();

				++rowcounter;

				if (table.empty()) 
				{
					table.closeFile();
					table.getFile().delete();
				} else 
				{
					pq.add(table); // add it back
				}
			}
		} 
		finally
		{
			fbw.close();
			for (TxtTable table : pq)
				table.closeFile();
		}

		return rowcounter;
	}