Merge text files

Hey all,
I've got two text files that need to be merged into another text file. One is a template where I have to insert various things, and one is list of the things I have to insert. I am familiar with BufferedReader and PrintWriter etc but was wondering on some tips on how to do it.
eg in the template.txt
I have
<<name>> <<address>>
Welcome, <<name>>, you live at <<addresss>>.
in the list.txt I have the name and address with delimiters which I believe you use Tokenizer for.
i have
Peter%n%
60 Black Road%a&
What is the order of things to process this and merge data in another text file?
Thanks for help.

Hi,
Here comes a complete example, but it differs from the approach ChuckBing gave you. I think this is more generic, has speed advantages, and is easier to adapt/maintain to other situations.
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Test {
    public static void main(String[] args) throws Exception {
        //Setup the generator
        //You want to read template from a file.       
        String template = "Welcome, <<name>>, you live at <<addresss>>"; 
        MessageGenerator generator = new MessageGenerator(template, "<<.*?>>");
        Record record = new Record();
        //Register callbacks for all tokens that you are interested in.
        generator.registerCallback("<<name>>", new AbstractCallback(record) {
            public String getValue(String token) {
                return record.getName();
        generator.registerCallback("<<addresss>>", new AbstractCallback(record) {
            public String getValue(String token) {
                return record.getAddress();
        //And test it.. You probably want to change this to a loop that
        //reads records, and writes the result to a file.
        record.setData("Kaj Bjurman%Any adress 21%");
        System.out.println(generator.getResult());
        record.setData("Another name%Another adress%");
        System.out.println(generator.getResult());
* Generates messages using a template, and callbacks
* @author Kaj Bjurman
class MessageGenerator {
    private String template;
    private Pattern pattern;
    private int previousMatchIndex;
    private Matcher matcher;
    private Map callbacks;   // Map<String token, Callback callback>
    private StringBuffer result;
    public MessageGenerator(String template, String tokenPattern) {
        this.template = template;
        this.pattern = Pattern.compile(tokenPattern);
        callbacks = new HashMap();
    public void reset() {
        previousMatchIndex = 0;
        matcher = pattern.matcher(template);
        result = new StringBuffer();
    public void registerCallback(String token, Callback callback) {
        callbacks.put(token, callback);
    public String getResult() {
        reset();
        while (matcher.find()) {
            result.append(template.substring(previousMatchIndex, matcher.start()));
            previousMatchIndex = matcher.end();
            String token = matcher.group();
            Callback callback = (Callback)callbacks.get(token);
            String value = token;
            if (callback != null) {
                value = callback.getValue(token);
            result.append(value);
        result.append(template.substring(previousMatchIndex));
        return result.toString();
    public static interface Callback {
        String getValue(String token);
* Class that represents a record of data.
* The data is expected to be in the form field1%field2%
* @author Kaj Bjurman
class Record {
    private String name;
    private String address;
    public void setData(String data) {
        String[] tmp = data.split("%");
        name = tmp[0];
        address = tmp[1];
    public String getName() {
        return name;
    public String getAddress() {
        return address;
* @author Kaj Bjurman
abstract class AbstractCallback implements MessageGenerator.Callback {
    protected Record record;
    public AbstractCallback(Record record) {
        this.record = record;
}/Kaj

Similar Messages

  • Merge text file with condition

    I have two text files (report1.txt and report2.txt) that I want to merge with conditions:
     - Matching rows that have same "ID" and same "TranVal", will keep only one instance
     - Mismatching rows that have same "ID" both rows from 2 file, but column "TranVal" has different value, then the row from report2.txt will replace row in report1.txt
     - Any "ID" that exists in one textfile but not the other one, will be copied to the final merged file
    report1.txt:
    TranDate,ID,TranVal,Comment
    061211,9840,40,done
    061211,9841,30,done
    061211,9842,28,done
    report2.txt:
    TranDate,ID,TranVal,Comment
    061211,9840,40,done
    061211,9841,89,done
    061211,9843,25,done
    Final result should be:
    merge.txt:
    TranDate,ID,TranVal,Comment
    061211,9840,40,done
    061211,9841,89,done
    061211,9842,28,done
    061211,9843,25,done

    Hi,
    I just checked Import-Csv option. I will be able to manage this problem if i can get it in CSV format and work with objects, BUT the problem is in my real file
    the file-format is different which is not comma-separated, instead have "-" as seperator. To simplify the problem i used comma in my question.
    TranDate,ID,TranVal,Comment
    061211-9840-40-done
    Could
    you suggest me if there is any way to convert "-" separators to CSV?

  • Merging text files along with their filename

    I am looking to merge a whole bunch of text files into one document. I am going to the Insert tab and selecting the drop down menu in Object to select text from file.  All of the text is merging in the one document correctly, but I am not
    getting the title/file name of the document inserted in the document and I would like that to be in there. Is there a way of doing this?

    Try the following macro. It assumes you're working with doc, docx & docm files. If not, change the 'doc' in the '*.doc' reference to whatever file type you're working with.
    Option Explicit
    Public oFolder As Object 'the folder object
    Public i As Long, j As Long
    Public DocTgt As Document
    Sub Main()
    ' Minimise screen flickering
    Application.ScreenUpdating = False
    Dim StrFolder As String
    ' Browse for the starting folder
    StrFolder = GetTopFolder
    If StrFolder = "" Then Exit Sub
    ' Initialize the counters
    i = 0: j = 0
    Set DocTgt = ActiveDocument
    ' Search the top-level folder
    Call GetFolder(StrFolder & "\")
    ' Return control of status bar to Word
    Application.StatusBar = ""
    ' Restore screen updating
    Application.ScreenUpdating = True
    MsgBox i & " of " & j & " files processed.", vbOKOnly
    End Sub
    Function GetTopFolder() As String
    GetTopFolder = ""
    Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
    If (Not oFolder Is Nothing) Then GetTopFolder = oFolder.Items.Item.Path
    Set oFolder = Nothing
    End Function
    Sub GetFolder(StrFolder As String)
    Dim strFile As String
    strFile = Dir(StrFolder & "*.doc")
    ' Process the files in the folder
    While strFile <> ""
      ' Update the status bar is just to let us know where we are
      Application.StatusBar = StrFolder & strFile
      Call UpdateFile(StrFolder & strFile)
      strFile = Dir()
    Wend
    End Sub
    Sub UpdateFile(strDoc As String)
    Dim Doc As Document
    ' Open the document
    Set Doc = Documents.Open(strDoc, AddToRecentFiles:=False, ReadOnly:=False, Format:=wdOpenFormatAuto, Visible:=False)
    With Doc
      If .ProtectionType = wdNoProtection Then
      With .Range.Sections
        With .First.Footers(wdHeaderFooterPrimary).Range
          .InsertBefore Doc.Name & vbCr
          While .Characters.Last.Previous = vbCr
            .Characters.Last.Previous = vbNullString
          Wend
        End With
        .Add Start:=wdSectionBreakNextPage
      End With
      DocTgt.Characters.Last.FormattedText = .Range.FormattedText
        ' Update the file counter for processed files
        i = i + 1
      End If
      ' Update the main file counter
      j = j + 1
      .Close SaveChanges:=False
    End With
    ' Let Word do its housekeeping
    DoEvents
    Set Doc = Nothing
    End Sub
    With this code, each merged file's name will be added to its footer.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  • How to merge text files and put the result in a text file.

    Hi,
    I am trying to merge the files(text) using OWB and I would like to put the result in a file. Could any one please explain how to do this.
    Thanks and regards
    Gowtham Sen.

    using the unix commnad 'cat' along with the redirect '>>' will concat the files into one target
    #this will create the target file and over-write it if it existed already
    cat file1 > target
    ##Now add the rest of the files to the target, without over-writing
    cat file2 >>target
    cat file3 >>target
    cat file16 >> target
    You can then use an external table on the target file.
    A nicer way would be to user a 'for loop', but this will work fine.

  • Variable text files in CS 5.5 data merge

    I have a document that I need to change the text in the document based on a variable in the data file that is being used for the data merge. For example if the are in group A the get letter from text document A, if they are in group B they get the letter from text document B.
    Can the data merge in CS 5.5 do this?

    not with text and not by itself, but a solution is workable.
    indesign's data merge can't place text files as if they were merging pictures, but it can place pictures from jpg, eps, pdf... if the text which changed was a picture, say a PDF, then this would be fine.
    as to telling data merge what is variable, indesign won't parse the data as such... it'll just put the data wherever the placeholders were. if you want if/else statements, these need to be done in the excel file first prior to saving as a text file for indesign.
    so yes, what the OP wants is do-able, but not "off of the shelf" - some manipulation in excel is required.

  • Merging different text files

    I am making a year book for wich I have many Word files and pictures. I think the data merge should be a perfect way to bring all these different texts and photo's into my lay out. But the text i can not get it to work. I can get the pictures to work but somehow i cannot load the different text files into the lay out? Can anyone tell if this is possible and how? thnx a lot (PS I am working with CS4)

    Here is one from
    Peter Kahrel
    // Description: Place multiple textfiles as one story
    #target indesign
    preset = '/d/test/*.rtf';
    app.wordRTFImportPreferences.useTypographersQuotes = true;
    app.wordRTFImportPreferences.convertPageBreaks = ConvertPageBreaks.none;
    app.wordRTFImportPreferences.importEndnotes = true;
    app.wordRTFImportPreferences.importFootnotes = true;
    app.wordRTFImportPreferences.importIndex = true;
    app.wordRTFImportPreferences.importTOC = false;
    app.wordRTFImportPreferences.importUnusedStyles = false;
    mask = prompt ('Enter a file path/mask.\r\r' +
        'Examples:\r' +
        'd:\\books\\test\\*.rtf   /d/books/test/*.rtf', preset);
    if (mask == null) exit();  // Cancel pressed
    ff = Folder (File (mask).path).getFiles (File (mask).name);
    if (ff.length > 0)
        placed = [];
        missed = [];
        tframe = app.documents.add().textFrames.add({geometricBounds : [36, 36, 400, 400]});
        placedstory = tframe.parentStory;
        app.scriptPreferences.userInteractionLevel =
            UserInteractionLevels.neverInteract;
        pb = initprogressbar (ff.length, 'Loading');
        for (i = 0; i < ff.length; i++)
            pb.value = i;
            try
                placedstory.insertionPoints[-1].place (ff[i]);
                placedstory.insertionPoints[-1].contents = '\r\r';
                placed.push (ff[i].name);
            catch (_)
                missed.push( ff[i].name );
        app.scriptPreferences.userInteractionLevel =
            UserInteractionLevels.interactWithAll;
        inform = '';
        if (placed.length > 0)
            inform = 'Placed ' + ff.length + ' files (in this order):\r\r' + placed.join ('\r');
        if (missed.length > 0)
            inform += '\r\rCould not place:\r\r' + missed.join ('\r');
        delete_empty_frames ();
        alert( inform );
    else
        alert (mask + ' not found.');
    // End
    function delete_empty_frames ()
        app.findGrepPreferences = app.changeGrepPreferences = null;
        app.findGrepPreferences.findWhat = '\\A\\Z';
        var empties = app.activeDocument.findGrep (true);
        for (var i = 0; i < empties.length; i++)
            empties[i].parentTextFrames[0].remove()
    function initprogressbar (stop, title)
        progresswindow = new Window('palette', title);
        progressbar = progresswindow.add ('progressbar', undefined, 1, stop);
        progressbar.preferredSize = [200,20];
        progresswindow.show ()
        return progressbar;

  • How to merge All text fiels into 1 text file to read into internal table

    Hi dudes,
      I have 3 text files in workstation. I need to everytime download these files in my internal table .
      But it takes long processing time .ie everytime it opens file read and close.
      Do u suggest for better performance for this? Like how i can meage all txt files in 1 txt file and then read once ito internal table.
      Hope i m clear to explain u my requirement.
      Gain Points

    It actually depends on your requirement(a standard answer from any SAP guy).
    Coming back to the question at hand:
    a) Can we merge these files ? My question to you :
    i) Are you downloading these to your presentation server from application server using WS_DOWNLOAD(I am using 4.5B) or CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD ?
    ii) What holds you back ?
    b) How do we parse multiple files contained in a single file ?
    Keep a delimiter which is unique only for file endings. That should do the trick.
    Regards,
    Subramanian V.

  • Merge two text files

    Need your help with merging two text source files into single table.  Each text file is single column containing names.  Let's say that file one is list of members in DEPARTMENT A and second file members of DEPARTMENT B.  Text files look
    something as follows:
    Filename: DEPARTMENT_A
    NAME (header)
    Steve
    Joe
    Mary
    Filename: DEPARTMENT_B
    NAME (header)
    Ron
    Joe
    Susie
    Ultimately, I need the resultant table data to look like this:
    NAME     DEPARTMENTS
    Steve     A
    Joe        A, B
    Mary      A 
    Ron        B
    etc.
    I think the solution involves derived columns, pivot, coalesce, but can't figure out how to put them together.  What do you recommend?  Thanks.

    You need a data flow task
    Inside that have two flat file sources connecting to both files. Following that have a derived column task to add department information (A,B). use a union all transform to merge both the inputs and finally use OLEDB destination to dump the result into table
    with two columns Name and Department.
    Then add a execute sql task to do update as below
    UPDATE t
    SET Department = Department + ', B'
    FROM Table t
    WHERE Department = 'A'
    AND EXISTS (SELECT 1
    FROM Table
    WHERE Name = t.Name
    AND Department = 'B'
    DELETE t
    FROM Table t
    WHERE Department = 'B'
    AND EXISTS (SELECT 1
    FROM Table
    WHERE Name = t.Name
    AND Department = 'A, B'
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Merging of two text files

    HI All,,
    I have a text file A with four fields and text file B with two fields. I wanted to club these two text files to a single text file with certain condition and that to be uploaded to a standard table through BDC.
    am I clear??
    Please suggest me how can I proceed for this.
    thanks,
    anil.

    Hi
    If you want to do this using a program
    Then use Function Module
    GUI_UPLOAD
    to load the two text files into two internal tables
    say itab1 for one with 4 fields
    and itab2 for the one with 2 fields
    Then you can join the two tables based on a key between the two into a final internal table with six fields
    use the function module GUI_DOWNLOAD to download the internal tab with six fields and you have the final file which you would need to upload for the BDC.
    Here also you can use GUI_UPLOAD to load the text file for the BDC program

  • Create a new dimension in business layer from Data source: text file on the web

    Hi,
    I have a text data source which is published every few hours that is accessible from a certain URL. I follow the instruction given in this http://scn.sap.com/docs/DOC-43144 - where it shows in great detail how to create the connection, data foundation as well as business layer to create a universe for this type of data.
    All is well - I can use this universe in my WEBI doc and display the data.
    However, in order for me to merge the data from this universe with another universe, I need to create  new dimension based on the data from the text file. The new dimension value is simply the first 4 characters of the Subject found in the text file. The "Subject" dimension is of variant type: varchar.
    Following the guide mentioned earlier, the connection is using SAP BO OpenConnectivity driver. And this driver limits severely the SQL statement that I can use to extract a substring of another string. Here's the screenshot of the SQl expression that I can use with this driver
    After hours of searching, I cannot find any other connection driver for a text file that's published on a certain URL. The BO OpenConnection driver is the best that I could find.
    So here are my problems
    1. one of my data source is a text file published on a web
    2. the only connection I can create does not allow me to create  new dimension in the universe to create an important column "subject ID"
    3. I can create the column in webi as a variable. But when I do so, I cannot merge it with existing dimension (webi not allowing to merge these 2 types). And without the merge, the flat file universe with my database universe can't be combined.
    I'm using WEBI Rich client version 4.1 SP3 Patch 1. Build 14.1.3.1300
    Is there any other idea that you can suggest without requiring to change the extracted data?
    Thanks.
    With warm regards

    Hi Bala,
    Were you able to find out a solution for the problem with uploading values for a variable from a text file on the web?  I am confronted with the same request from users.
    Thanks,
    BQ

  • Adding large arrays to a text file as new columns

    I am trying to merge several large text data files into a single file in Labview 8.0.  The files are too large to read in all at once (9-15 million lines each), so decided I need to read them in as smaller chunks, combine the arrays, and write them to a new file.
    The reason there are three separate data files was for speed and streaming purposes in the project, and the users wanted the raw, unadulterated data written to file before any kind of manipulation took place. 
    My VI:
    1.  Takes a header generated from another VI and writes it to the output file.
    2.  Creates a time column based on sample rate and the total number of data points
    3.  Reads in 3 files that each have text data (each data point is 9 bytes wide, there are up to 15 million data points per file.
    4.  Each iteration of the for loop writes a chunk of 10 to 100 thousand points (Somewhere in there seems to be the fastest it will do), formatted with the time column on the left, then the three data columns, until it's done.  I haven't quite figured out how to write the last iteration if there are fewer data points than the chunk size.
    Anyways, the main thing I was looking for was suggestions on how to do this faster.  It takes about a minute per million points on my laptop to do this operation, and though I recognize it is a lot of data to be moving around, this speed is painfully slow.  Any ideas?
    Attachments:
    Merge Fast Data.vi ‏67 KB

    Thanks for the tip.  I put the constants outside the array and noticed a little improvement in the speed.  I know I could improve the speed by using the binary file VI's but I need the files as tab delimited text files to import them into MATLAB for another group to do analysis.  I have not had any luck converting binary files into text files.  Is there an easy way to do that?  I don't know enough about binary file systems to use them.  I looked at the high speed data logger examples but they seemed complicated and hard to adapt to what I need to do.  Creating the binary header file seemed like a chore. 
    I am up for more advice on the VI I posted, or suggestions on different ways to convert a binary file to a MATLAB readable text file.
    Thanks!

  • Problem in Merging PDF files

    Need to print batches of PDF.<br />The command copy *.PDF > LPT1: (redirected by NET USE) doesn't work.<br />On the printer I get an error message. All files are sent in one file.<br />.<br />I guess this is related to the PDF header which is not set correctly for the second PDF copied.<br />I mean, according to the PDF Reference guide, the proper syntax for a PDF file header is for the "%PDF-<version>" comment to be the first line of the PDF file. The recommended second line is a comment line with four binary characters to indicate the file contains binary information.<br />.<br />Acrobat requires only that the header appears somewhere within the first 1024 bytes of the file.<br />.<br />I guess the Rip is not able to convert PDF into PS before its interpretation as the second header exceeds 1024. Even the combined file has %%EOF before each PDF Header, this is probably not enough to merge them without problem.<br />.<br />Did you experience the same ?<br />Thanks for your comments.<br />Regards.<br />Franck

    You can build your own PDF merge utility using the PDF Merge and split libraries for .NET from from http://www.dotnet-reporting.com or http://www.winnovative-software.com .
    You can use it to merge PDF files, html files, text files and images,
    set the page orientation, compression level and page size.
    All this can be accomplished with only a few lines of code:
    PdfDocumentOptions pdfDocumentOptions = new PdfDocumentOptions();
    pdfDocumentOptions.PdfCompressionLevel = PDFCompressionLevel.Normal;
    pdfDocumentOptions.PdfPageSize = PdfPageSize.A4; pdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait;
    PDFMerge pdfMerge = new PDFMerge(pdfDocumentOptions);
    pdfMerge.AppendPDFFile(pdfFilePath);
    pdfMerge.AppendImageFile(imageFilePath);
    pdfMerge.AppendTextFile(textFilePath);
    pdfMerge.AppendEmptyPage();
    pdfMerge.AppendHTMLFile(htmlFilePath);
    pdfMerge.SaveMergedPDFToFile(outFile);

  • Merging Different Files Using XI

    Hi All,
    I hav a scenrio where i have to merger 'n' no of files into a single file and push it to some location on the FTP.
    <u><b>Details:</b></u>:
    <u><b>Source</b></u>
    <u><i>File1</i></u>
    abc
    def
    ghi
    <u><i>File2</i></u>:
    xxx
    yyy
    zzz
    <u><i>File3</i></u>:
    ppppppppppp
    qqqqqqq
    rrrrrrrrrrrrrr
    <u><i>File4</i></u>:
    uuuuuuuuu
    <u><i>File5</i></u>:
    <u><i>File6</i></u>:
    <u><i>Filen</i></u>:
    <u><b>Target</b></u>
    <u><i><b><b>MyFile:</b></b></i></u>:
    abc
    def
    ghi
    xxx                 (Content of File2)
    yyy
    zzz
    ppppppppppp                 (Content of File3)
    qqqqqqq
    rrrrrrrrrrrrrr
    uuuuuuuuu                    (Content of File4)
    <u><i>File5</i></u>:             (Content of File5)
    <u><i>File6</i></u>:              (Content of File6)
    <u><i>Filen</i></u>:              (Content of Filen)
    Each of the Source file contains different Message Type from other files. All these files are on local drive.
    Can any one help me out in this regard? Any help wud b highly appreciated.
    Thnx in Advance
    Anil

    Hi All,
    First of all,thanx a lot for ur answers.
    1) I dont wanna use BPM coz it doesn't make sense to create N different messages types and put it in a fork.
    2) Even though I go for a BPM, i can't acheive this as i dont have any common field among all the message type which ensures the Correlation.
    These are just text files which have to be merged in the same order of their creation. we dont need any mapping r any other XI functionality. I just wanna create something like a batch process in XI which merges all the files and moves to a particular location. I hav to do this in XI as i can monitor the whole scenario end to end with in XI.
    Any suggestion guys?
    Anil

  • JS - Save File as Field Name in the Data Merge Source File

    Hi All - I need some help...
    I'm trying to figure out the JavaScript code to save an indd file using the data merge source file field value.
    As an example...
    Let's say I have an invoice template called template.indd that is linked to invoice.txt.
    To make it easy, let's say the text file has 1 field called "invoice number" with a value of 123
    I run data merge.
    Now I want to save the merged indd file as 123.indd
    I've got everything figured out in JS except getting the source text file data into a variable to use when saving.  This one's been giving me fits for hours!
    Is this possible??
    Thanks very much

    Did you ever get this to work?

  • Insufficient System Resources when merging large files

    My client is running on Windows Server 2003, 64 bit. He has 30 gig of RAM and a large amount of file storage. The drives are NTFS.
    I have a program that produces a number of text files from different processes, and then merges them when done. After running the code for many days (we're working with a lot of data), the merge process is failing with "Insufficient System Resources Exist to complete the requested process".
    Insufficient system resources exist to complete the requested service
    java.io.IOException: Insufficient system resources exist to complete the requested service
    at java.io.FileOutputStream.writeBytes(Native Method)
    at java.io.FileOutputStream.write(Unknown Source)
    at sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)
    at sun.nio.cs.StreamEncoder.implWrite(Unknown Source)
    at sun.nio.cs.StreamEncoder.write(Unknown Source)
    at java.io.OutputStreamWriter.write(Unknown Source)
    at java.io.BufferedWriter.write(Unknown Source)
    at functionality.ScenarioThreadedLoanProcessor.processLoans(ScenarioThreadedLoanProcessor.java:723)
    at functionality.ScenarioThreadedLoanProcessor.construct(ScenarioThreadedLoanProcessor.java:227)
    at utility.SwingWorker$2.run(SwingWorker.java:131)
    at java.lang.Thread.run(Unknown Source)
    I've investigated this problem in other places, and most of the answers seem to not apply to my case.
    I've looked a this: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4938442
    But I am not using file channels (I don't think...), and I am copying data in chunks of <32MB.
    Here's the relevant code (I realize I don't need to be re-allocating the buffer, that's a legacy from an older version, but I don't think that's the cause.)
    There are usually four threads, 1-4 reports, and 1 scenario, so this loop shouldn't be executing thousands and thousands of times.
    for (int scenario = 0; scenario < scenarios.size(); scenario++)
                        for (int report = 0; report < reportPages.size(); report++)
                             for (LoanThread ln : loanThreads)
                                  BufferedReader br = new BufferedReader(new FileReader(new File(ln.reportPtr.get(
                                            (scenario * reportPages.size()) + report).getFileName())));
                                  br.readLine();//header, throw away
                                  BufferedWriter bw = new BufferedWriter(new FileWriter(formReport.get((scenario * reportPages.size()) + report)
                                            .getFileName(), true));//append
                                  char[] bu = new char[1024 * 1024 * 16];
                                  int charsRead = 0;
                                  while ((charsRead = br.read(bu)) != -1)
                                       bw.write(bu, 0, charsRead);
                                  bw.flush();
                                  bw.close();
                                  br.close();
                                  File f = new File(ln.reportPtr.get((scenario * reportPages.size()) + report).getFileName());
                                  f.delete();
    Any thoughts?Edited by: LizardSF on Jul 29, 2011 8:11 AM
    Edited by: sabre150 on 29-Jul-2011 09:02
    Added [ code] tags to make the code (more) readable

    1) You can allocate the buffer at the start of the outer loop to save the GC working overtime. You might even be able to move it out of the loops all together but I would need to see more code to be sure of that.+1. Exactly. This is the most important change you must do.
    The other change I would make is to reduce the buffer size. The disk only works in units of 4-16k at a time anyway. You will be surprised how much you can reduce it without affecting performance at all. I would cut it down to no more than a megabyte.
    You could also speed it up probably by a factor of at least two by using InputStreams and OutputStreams and a byte[] buffer, instead of Readers and Writers and char[], as you're only copying the file anyway. Also, those BufferedReaders and Writers are contributing nothing much, in fact nothing after the readLine(), as you are already using a huge buffer. Finally, you should also investigate FileChannel.transferTo() to get even more performance, and no heap memory usage whatsoever. Note that like your copy loop above, you have to check the result it returns and loop until the copy is complete. There are also upper limits on the transferCount that are imposed by the operating system and will cause exceptions, so again don't try to set it too big. A megabyte is again sufficient.

Maybe you are looking for

  • How to change the same cell in multiple tables at the same time

    help if you can, i have a workbook workbook has 10 sheets each sheet has 1 table when in excel you were able to select a sheet then hold control and select another, this would group the sheet as if to make them the same. change a single cell in one o

  • How to upload multiple items of sales order?

    I have extracted open sales order and transferred it to an excel file. Some SO doument has multiple items on one SO. If I will upload that SO document (with multiple items) into a new server, how am I suppose to itemize that this document has multipl

  • "The Document Could Not be Printed" "There were no pages selected to print"

    OSX 10.6.6 Acrobat Pro 9.4.1 I am getting this error when printed from certain PDF files. My best guess is it is a font conflict because if I change the font in the document and re-export the file the document prints fine. But changing the font (and

  • IMac no video, fans and cd drive work?

    A friend asked me to take a look at his computer. It is an iMac, 24" display, model MA878LL. I plug the iMac in and press the power button. The fans run and I can insert and eject CDs but there is no video. I tried pulling the memory and resetting it

  • Retrive Cookie Information in the Apache Access Log Files

    Hi All, Can anyone give me the solution or any link to follow the steps for retriving cookie information and user information in the Apache Access log files using httpd.conf file. we are using Oracle Appserver 10.1.2 Version and we have specfied belo