How to merge two csv files with same header columns into another csv file using javaHow can I concatenate two arrays in Java?How do I call one constructor from another in Java?How do I create a Java string from the contents of a file?How do I create a file and write to it in Java?How to avoid Java code in JSP files?How to sort CSV file by header?Merging a bunch of csv files into one with headersExtract and merge columns in a CSVcompare a set of strings from one csv file in another csv file using Unix Shell scriptScript to map columns in two csv files

The IT department bottlenecks progress. How should I handle this?

Creepy dinosaur pc game identification

Not using 's' for he/she/it

When were female captains banned from Starfleet?

Basic combinatorial probability problem

How could a planet have erratic days?

What is the evidence for the "tyranny of the majority problem" in a direct democracy context?

How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?

Why did the EU agree to delay the Brexit deadline?

Open a doc from terminal, but not by its name

What changes for testers when they are testing in agile environments?

How to create ADT in Haskell?

How to explain what's wrong with this application of the chain rule?

Explaining alternative travel routes when going to the USA

Lowest total scrabble score

Python scanner for the first free port in a range

Are the IPv6 address space and IPv4 address space completely disjoint?

Why a symmetric relation is defined: ∀x∀y( xRy⟹yRx) and not ∀x∀y (xRy⟺yRx)?

Can I sign legal documents with a smiley face?

Is aluminum electrical wire used on aircraft?

Travelling outside the UK without a passport

Is (0,1] a closed or open set?

Is there any references on the tensor product of presentable (1-)categories?

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)



How to merge two csv files with same header columns into another csv file using java


How can I concatenate two arrays in Java?How do I call one constructor from another in Java?How do I create a Java string from the contents of a file?How do I create a file and write to it in Java?How to avoid Java code in JSP files?How to sort CSV file by header?Merging a bunch of csv files into one with headersExtract and merge columns in a CSVcompare a set of strings from one csv file in another csv file using Unix Shell scriptScript to map columns in two csv files













0















csv file 1:



a|b|c
a|a|a
b|b|b


csv file 2:



a|b|c
c|c|c
d|d|d


output csv file:



a|b|c
a|a|a
b|b|b
c|c|c
d|d|d


here's my code i tried to merge but the header is repeating twice :
and when it comes to merging two files into single alternate csv file then also iam facing the same issue as the above the header columns gets repeated everytime what am i supposed to do to ignore it.
here's my code below



 public static void main(String[] args) throws IOException 
{
// PrintWriter object for file3.txt
PrintWriter pw = new PrintWriter("file3.txt");

// BufferedReader object for file1.txt
BufferedReader br1 = new BufferedReader(new FileReader("file1.txt"));
BufferedReader br2 = new BufferedReader(new FileReader("file2.txt"));


String line1 = br1.readLine();
String line2 = br2.readLine();

// loop to copy lines of
// file1.txt and file2.txt
// to file3.txt alternatively
while (line1 != null || line2 !=null)

if(line1 != null)

pw.println(line1);
line1 = br1.readLine();


if(line2 != null)

pw.println(line2);
line2 = br2.readLine();



pw.flush();

// closing resources
br1.close();
br2.close();
pw.close();


howw to skip the header column in the output file










share|improve this question
























  • So you want a file with only the unique lines of all input files?

    – Robert Kock
    2 days ago











  • Are the input files sorted? Is the order of the lines in the output file important?

    – Robert Kock
    2 days ago











  • no the order is not important but the data should not be skipped if they have duplicates they should not be skipped

    – pragadeeshwaran venkatachalam
    2 days ago











  • i have added another code with two files merged to single file its also getting the same issue how to ignore the header column

    – pragadeeshwaran venkatachalam
    2 days ago















0















csv file 1:



a|b|c
a|a|a
b|b|b


csv file 2:



a|b|c
c|c|c
d|d|d


output csv file:



a|b|c
a|a|a
b|b|b
c|c|c
d|d|d


here's my code i tried to merge but the header is repeating twice :
and when it comes to merging two files into single alternate csv file then also iam facing the same issue as the above the header columns gets repeated everytime what am i supposed to do to ignore it.
here's my code below



 public static void main(String[] args) throws IOException 
{
// PrintWriter object for file3.txt
PrintWriter pw = new PrintWriter("file3.txt");

// BufferedReader object for file1.txt
BufferedReader br1 = new BufferedReader(new FileReader("file1.txt"));
BufferedReader br2 = new BufferedReader(new FileReader("file2.txt"));


String line1 = br1.readLine();
String line2 = br2.readLine();

// loop to copy lines of
// file1.txt and file2.txt
// to file3.txt alternatively
while (line1 != null || line2 !=null)

if(line1 != null)

pw.println(line1);
line1 = br1.readLine();


if(line2 != null)

pw.println(line2);
line2 = br2.readLine();



pw.flush();

// closing resources
br1.close();
br2.close();
pw.close();


howw to skip the header column in the output file










share|improve this question
























  • So you want a file with only the unique lines of all input files?

    – Robert Kock
    2 days ago











  • Are the input files sorted? Is the order of the lines in the output file important?

    – Robert Kock
    2 days ago











  • no the order is not important but the data should not be skipped if they have duplicates they should not be skipped

    – pragadeeshwaran venkatachalam
    2 days ago











  • i have added another code with two files merged to single file its also getting the same issue how to ignore the header column

    – pragadeeshwaran venkatachalam
    2 days ago













0












0








0








csv file 1:



a|b|c
a|a|a
b|b|b


csv file 2:



a|b|c
c|c|c
d|d|d


output csv file:



a|b|c
a|a|a
b|b|b
c|c|c
d|d|d


here's my code i tried to merge but the header is repeating twice :
and when it comes to merging two files into single alternate csv file then also iam facing the same issue as the above the header columns gets repeated everytime what am i supposed to do to ignore it.
here's my code below



 public static void main(String[] args) throws IOException 
{
// PrintWriter object for file3.txt
PrintWriter pw = new PrintWriter("file3.txt");

// BufferedReader object for file1.txt
BufferedReader br1 = new BufferedReader(new FileReader("file1.txt"));
BufferedReader br2 = new BufferedReader(new FileReader("file2.txt"));


String line1 = br1.readLine();
String line2 = br2.readLine();

// loop to copy lines of
// file1.txt and file2.txt
// to file3.txt alternatively
while (line1 != null || line2 !=null)

if(line1 != null)

pw.println(line1);
line1 = br1.readLine();


if(line2 != null)

pw.println(line2);
line2 = br2.readLine();



pw.flush();

// closing resources
br1.close();
br2.close();
pw.close();


howw to skip the header column in the output file










share|improve this question
















csv file 1:



a|b|c
a|a|a
b|b|b


csv file 2:



a|b|c
c|c|c
d|d|d


output csv file:



a|b|c
a|a|a
b|b|b
c|c|c
d|d|d


here's my code i tried to merge but the header is repeating twice :
and when it comes to merging two files into single alternate csv file then also iam facing the same issue as the above the header columns gets repeated everytime what am i supposed to do to ignore it.
here's my code below



 public static void main(String[] args) throws IOException 
{
// PrintWriter object for file3.txt
PrintWriter pw = new PrintWriter("file3.txt");

// BufferedReader object for file1.txt
BufferedReader br1 = new BufferedReader(new FileReader("file1.txt"));
BufferedReader br2 = new BufferedReader(new FileReader("file2.txt"));


String line1 = br1.readLine();
String line2 = br2.readLine();

// loop to copy lines of
// file1.txt and file2.txt
// to file3.txt alternatively
while (line1 != null || line2 !=null)

if(line1 != null)

pw.println(line1);
line1 = br1.readLine();


if(line2 != null)

pw.println(line2);
line2 = br2.readLine();



pw.flush();

// closing resources
br1.close();
br2.close();
pw.close();


howw to skip the header column in the output file







java performance csv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







pragadeeshwaran venkatachalam

















asked 2 days ago









pragadeeshwaran venkatachalampragadeeshwaran venkatachalam

34




34












  • So you want a file with only the unique lines of all input files?

    – Robert Kock
    2 days ago











  • Are the input files sorted? Is the order of the lines in the output file important?

    – Robert Kock
    2 days ago











  • no the order is not important but the data should not be skipped if they have duplicates they should not be skipped

    – pragadeeshwaran venkatachalam
    2 days ago











  • i have added another code with two files merged to single file its also getting the same issue how to ignore the header column

    – pragadeeshwaran venkatachalam
    2 days ago

















  • So you want a file with only the unique lines of all input files?

    – Robert Kock
    2 days ago











  • Are the input files sorted? Is the order of the lines in the output file important?

    – Robert Kock
    2 days ago











  • no the order is not important but the data should not be skipped if they have duplicates they should not be skipped

    – pragadeeshwaran venkatachalam
    2 days ago











  • i have added another code with two files merged to single file its also getting the same issue how to ignore the header column

    – pragadeeshwaran venkatachalam
    2 days ago
















So you want a file with only the unique lines of all input files?

– Robert Kock
2 days ago





So you want a file with only the unique lines of all input files?

– Robert Kock
2 days ago













Are the input files sorted? Is the order of the lines in the output file important?

– Robert Kock
2 days ago





Are the input files sorted? Is the order of the lines in the output file important?

– Robert Kock
2 days ago













no the order is not important but the data should not be skipped if they have duplicates they should not be skipped

– pragadeeshwaran venkatachalam
2 days ago





no the order is not important but the data should not be skipped if they have duplicates they should not be skipped

– pragadeeshwaran venkatachalam
2 days ago













i have added another code with two files merged to single file its also getting the same issue how to ignore the header column

– pragadeeshwaran venkatachalam
2 days ago





i have added another code with two files merged to single file its also getting the same issue how to ignore the header column

– pragadeeshwaran venkatachalam
2 days ago












1 Answer
1






active

oldest

votes


















0














Just skip the first lines of second and subsequent CSV files:



 for (int i = 0; i < fileNames.length; i++) 
System.out.println("Reading from " + fileNames[i]);

File f = new File(dir, fileNames[i]);

BufferedReader br = new BufferedReader(new FileReader(f));

String line = br.readLine();
if (i > 0)
line = br.readLine(); //just skip the first line

while (line != null)
pw.println(line);
line = br.readLine();


pw.flush();






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281263%2fhow-to-merge-two-csv-files-with-same-header-columns-into-another-csv-file-using%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Just skip the first lines of second and subsequent CSV files:



     for (int i = 0; i < fileNames.length; i++) 
    System.out.println("Reading from " + fileNames[i]);

    File f = new File(dir, fileNames[i]);

    BufferedReader br = new BufferedReader(new FileReader(f));

    String line = br.readLine();
    if (i > 0)
    line = br.readLine(); //just skip the first line

    while (line != null)
    pw.println(line);
    line = br.readLine();


    pw.flush();






    share|improve this answer





























      0














      Just skip the first lines of second and subsequent CSV files:



       for (int i = 0; i < fileNames.length; i++) 
      System.out.println("Reading from " + fileNames[i]);

      File f = new File(dir, fileNames[i]);

      BufferedReader br = new BufferedReader(new FileReader(f));

      String line = br.readLine();
      if (i > 0)
      line = br.readLine(); //just skip the first line

      while (line != null)
      pw.println(line);
      line = br.readLine();


      pw.flush();






      share|improve this answer



























        0












        0








        0







        Just skip the first lines of second and subsequent CSV files:



         for (int i = 0; i < fileNames.length; i++) 
        System.out.println("Reading from " + fileNames[i]);

        File f = new File(dir, fileNames[i]);

        BufferedReader br = new BufferedReader(new FileReader(f));

        String line = br.readLine();
        if (i > 0)
        line = br.readLine(); //just skip the first line

        while (line != null)
        pw.println(line);
        line = br.readLine();


        pw.flush();






        share|improve this answer















        Just skip the first lines of second and subsequent CSV files:



         for (int i = 0; i < fileNames.length; i++) 
        System.out.println("Reading from " + fileNames[i]);

        File f = new File(dir, fileNames[i]);

        BufferedReader br = new BufferedReader(new FileReader(f));

        String line = br.readLine();
        if (i > 0)
        line = br.readLine(); //just skip the first line

        while (line != null)
        pw.println(line);
        line = br.readLine();


        pw.flush();







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 days ago









        Jaja

        516




        516










        answered 2 days ago









        Pavel SmirnovPavel Smirnov

        1,177214




        1,177214





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281263%2fhow-to-merge-two-csv-files-with-same-header-columns-into-another-csv-file-using%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해