Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
|
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 23rd, 2004, 03:17 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default Concatenating files modification

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?







Similar Threads
Thread Thread Starter Forum Replies Last Post
concatenating records rashi Access VBA 9 November 6th, 2008 05:07 PM
Concatenating like records pvasudevan SQL Server 2000 35 August 14th, 2008 09:28 AM
Concatenating many XML files srivalli9 XML 4 March 30th, 2006 03:05 AM
concatenating arrays allee_man BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 August 19th, 2005 08:55 AM
Concatenating many XML files srivalli9 J2EE 0 November 12th, 2003 03:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.