I want to merge multiple .eml files into one. By using simple merge technique I am able to merge it. But while trying to open it, i can only find one email inside it. Can anyone help me with it, as i am not sure what is wrong.
below is the code snip..
public static void mergeFiles(List<InputStream> source, File mergedFile) throws FileNotFoundException, IOException {
FileWriter fstream = null;
BufferedWriter out = null;
try {
fstream = new FileWriter(mergedFile, true);
out = new BufferedWriter(fstream);
} catch (IOException e1) {
e1.printStackTrace();
}
// for (InputStream f : source) {
Iterator itr = source.iterator();
while(itr.hasNext())
{
//System.out.println("merging: " + f.getName());
InputStream fis;
fis = (InputStream) itr.next();
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
String aLine;
while ((aLine = in.readLine()) != null) {
out.write(aLine);
out.newLine();
}
in.close();
}
out.close();
}