What I want to do, is add an extra tag before the beginning & end of the concatenated files. Current code:
Code:
public static void concatenate(File[] args, File dest) throws IOException {
FileChannel in = null, out = null;
File source;
long pos = 0;
long size;
try {
out = new FileOutputStream(dest).getChannel();
for(int i = 0; i < args.length; i++){
source = args[i];
in = new FileInputStream(source).getChannel();
size = in.size();
MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, pos, size);
out.write(buf);
pos+=size;
in.close();
}
} finally {
if (in != null) in.close();
if (out != null) out.close();
}
}
eg. want to change it to concatenate(File[] args, File dest, String tag)
where it adds: <tag> to the beginning and </tag> to the end. Could do it using filewriter, but then I'd have to rewrite the rest of the function. I've been trying to copy over a string, but seems to either overwrite info, or have random data as a result. Does anyone know how to use the MappedByteBuffer correctly?