CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Java Programming > Java Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Java Programming Ask your Java programming question and help out others with theirs.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 3rd, 2009, 06:25 PM
    starwok starwok is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 3
    starwok is an unknown quantity at this point (<10)
    Merging two data file

    I'm supposed to merge a ordered data of two files into a third file, keeping the data in order. I'm suppose to create a MergeFiles application that merges the integers ordered from low to high in two files into a third file, keeping the order from low to high. Then should merge the two files by taking one element at a time from each, and the third file should contain the numbers from both file from lowest to highest. so, i saved the numbers in wordpad as data1.txt, and data2.txt.

    Data1: 11 25 36 45 56 78 90
    Data2: 1 3 5 7 54 32 78 99

    I can't compile my program because there are still errors and missing codes... can someone help me edit it, and is this how i do it according to the requirements. thx.


    so far:

    package mergetwofiles;

    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.FileWriter;

    public class Main {


    public static void main(String[] args) {
    FileReader file1=new FileReader("Data1.txt");
    FileReader file2=new FileReader("Data2.txt");
    BufferedReader br1 = new BufferedReader of(file1);
    BufferedReader br2 = new BufferedReader of(file2);

    String temp1, temp2;
    while(br1.readLine() !=null)
    {
    temp1=br1.readLine()+temp1;
    }
    while(br2.readLine()!=null)
    {
    temp2=br2.readLine()+temp2;
    }
    String temp = temp1 + temp2;
    FileWriter fw=new FileWriter("data3.txt");
    char buffer[]=new char[temp.length];
    temp.getChars(0,temp.length(),buffer,0);
    fw.write(buffer);
    file1.close();
    file2.close();
    fw.close();
    }
    }
    Reply With Quote
      #2    
    Old November 4th, 2009, 08:50 AM
    ProgramThis ProgramThis is offline
    Member +
     
    Join Date: Feb 2008
    Posts: 681
    ProgramThis is on a distinguished road (40+)
    Re: Merging two data file

    I am willing to bet that one error it is telling you is that there are uncaught exceptions. You cannot perform file I/O without catching/throwing exceptions.
    Reply With Quote
      #3    
    Old November 4th, 2009, 09:17 AM
    keang keang is offline
    Elite Member
     
    Join Date: May 2006
    Location: UK
    Posts: 2,104
    keang is a jewel in the rough (200+)keang is a jewel in the rough (200+)keang is a jewel in the rough (200+)
    Re: Merging two data file

    Quote:
    I can't compile my program because there are still errors and missing codes... can someone help me edit it, and is this how i do it according to the requirements. thx.
    It would help if you posted the errors you got when compiling and also explain what code you are missing. Also please use code tags when posting code.

    As well as ProgramThis's correct observation, a more fundamental problem is on these 2 lines:
    Code:
    BufferedReader br1 = new BufferedReader of(file1);
    BufferedReader br2 = new BufferedReader of(file2);
    What's the 'of' for?
    Reply With Quote
      #4    
    Old November 4th, 2009, 09:26 AM
    keang keang is offline
    Elite Member
     
    Join Date: May 2006
    Location: UK
    Posts: 2,104
    keang is a jewel in the rough (200+)keang is a jewel in the rough (200+)keang is a jewel in the rough (200+)
    Re: Merging two data file

    I've just noticed this is a duplicate of this thread
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Java Programming > Java Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 01:34 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009