How to read specific columns in CSV file java












-1














my CSV file looks like this:



Id;date;code;type;category;name;position;formula
10;;;2010-02-01;;000010;P;W;NormalDays;10;#formelTest
55;;;2050-05-02;;000055;D;C;SpecificDays;55;#formelTest2
60;;;2301-08-03;;000060;A;C;NotNormalDays;60;#formelBlablblabla
75;;;2012-01-08;;000075;P;W;VulgaryDays;75;@formellbalbalbalbababa


I would like to read from it lines by line only from only first column id and last column formula. How can I do this? Thanks for help.



The code:



File file = new File("Filename.csv");
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
for (String line : lines)
{
String array = line.split(",");
System.out.println(array[0]);
}









share|improve this question
























  • Do you have a sample code of what have you do?
    – albert
    Jul 14 '17 at 10:55










  • File file = new File("Filename.csv"); List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); for (String line : lines) { String array = line.split(","); System.out.println(array[0]); }
    – Kima321
    Jul 14 '17 at 10:57










  • Simple read file. I dont have idea how can I read specific columns...
    – Kima321
    Jul 14 '17 at 10:57










  • It would be better to edit your question and add the code, for StackOverflow question guidelines
    – albert
    Jul 14 '17 at 10:58










  • Why do you do a split with ',' if you use ';'?
    – albert
    Jul 14 '17 at 10:59
















-1














my CSV file looks like this:



Id;date;code;type;category;name;position;formula
10;;;2010-02-01;;000010;P;W;NormalDays;10;#formelTest
55;;;2050-05-02;;000055;D;C;SpecificDays;55;#formelTest2
60;;;2301-08-03;;000060;A;C;NotNormalDays;60;#formelBlablblabla
75;;;2012-01-08;;000075;P;W;VulgaryDays;75;@formellbalbalbalbababa


I would like to read from it lines by line only from only first column id and last column formula. How can I do this? Thanks for help.



The code:



File file = new File("Filename.csv");
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
for (String line : lines)
{
String array = line.split(",");
System.out.println(array[0]);
}









share|improve this question
























  • Do you have a sample code of what have you do?
    – albert
    Jul 14 '17 at 10:55










  • File file = new File("Filename.csv"); List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); for (String line : lines) { String array = line.split(","); System.out.println(array[0]); }
    – Kima321
    Jul 14 '17 at 10:57










  • Simple read file. I dont have idea how can I read specific columns...
    – Kima321
    Jul 14 '17 at 10:57










  • It would be better to edit your question and add the code, for StackOverflow question guidelines
    – albert
    Jul 14 '17 at 10:58










  • Why do you do a split with ',' if you use ';'?
    – albert
    Jul 14 '17 at 10:59














-1












-1








-1







my CSV file looks like this:



Id;date;code;type;category;name;position;formula
10;;;2010-02-01;;000010;P;W;NormalDays;10;#formelTest
55;;;2050-05-02;;000055;D;C;SpecificDays;55;#formelTest2
60;;;2301-08-03;;000060;A;C;NotNormalDays;60;#formelBlablblabla
75;;;2012-01-08;;000075;P;W;VulgaryDays;75;@formellbalbalbalbababa


I would like to read from it lines by line only from only first column id and last column formula. How can I do this? Thanks for help.



The code:



File file = new File("Filename.csv");
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
for (String line : lines)
{
String array = line.split(",");
System.out.println(array[0]);
}









share|improve this question















my CSV file looks like this:



Id;date;code;type;category;name;position;formula
10;;;2010-02-01;;000010;P;W;NormalDays;10;#formelTest
55;;;2050-05-02;;000055;D;C;SpecificDays;55;#formelTest2
60;;;2301-08-03;;000060;A;C;NotNormalDays;60;#formelBlablblabla
75;;;2012-01-08;;000075;P;W;VulgaryDays;75;@formellbalbalbalbababa


I would like to read from it lines by line only from only first column id and last column formula. How can I do this? Thanks for help.



The code:



File file = new File("Filename.csv");
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
for (String line : lines)
{
String array = line.split(",");
System.out.println(array[0]);
}






java csv readfile






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 14 '17 at 18:15









albert

1,25131728




1,25131728










asked Jul 14 '17 at 10:53









Kima321

1515




1515












  • Do you have a sample code of what have you do?
    – albert
    Jul 14 '17 at 10:55










  • File file = new File("Filename.csv"); List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); for (String line : lines) { String array = line.split(","); System.out.println(array[0]); }
    – Kima321
    Jul 14 '17 at 10:57










  • Simple read file. I dont have idea how can I read specific columns...
    – Kima321
    Jul 14 '17 at 10:57










  • It would be better to edit your question and add the code, for StackOverflow question guidelines
    – albert
    Jul 14 '17 at 10:58










  • Why do you do a split with ',' if you use ';'?
    – albert
    Jul 14 '17 at 10:59


















  • Do you have a sample code of what have you do?
    – albert
    Jul 14 '17 at 10:55










  • File file = new File("Filename.csv"); List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); for (String line : lines) { String array = line.split(","); System.out.println(array[0]); }
    – Kima321
    Jul 14 '17 at 10:57










  • Simple read file. I dont have idea how can I read specific columns...
    – Kima321
    Jul 14 '17 at 10:57










  • It would be better to edit your question and add the code, for StackOverflow question guidelines
    – albert
    Jul 14 '17 at 10:58










  • Why do you do a split with ',' if you use ';'?
    – albert
    Jul 14 '17 at 10:59
















Do you have a sample code of what have you do?
– albert
Jul 14 '17 at 10:55




Do you have a sample code of what have you do?
– albert
Jul 14 '17 at 10:55












File file = new File("Filename.csv"); List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); for (String line : lines) { String array = line.split(","); System.out.println(array[0]); }
– Kima321
Jul 14 '17 at 10:57




File file = new File("Filename.csv"); List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); for (String line : lines) { String array = line.split(","); System.out.println(array[0]); }
– Kima321
Jul 14 '17 at 10:57












Simple read file. I dont have idea how can I read specific columns...
– Kima321
Jul 14 '17 at 10:57




Simple read file. I dont have idea how can I read specific columns...
– Kima321
Jul 14 '17 at 10:57












It would be better to edit your question and add the code, for StackOverflow question guidelines
– albert
Jul 14 '17 at 10:58




It would be better to edit your question and add the code, for StackOverflow question guidelines
– albert
Jul 14 '17 at 10:58












Why do you do a split with ',' if you use ';'?
– albert
Jul 14 '17 at 10:59




Why do you do a split with ',' if you use ';'?
– albert
Jul 14 '17 at 10:59












2 Answers
2






active

oldest

votes


















0














Completing your code:



File file = new File("Filename.csv"); 
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
for (String line : lines) {
String array = line.split(";");
System.out.println(array[0]+" "+array[array.length-1]);
}


You will notice that I changed the comma to a semi-colon as the split separator and added a bit to the println, which will be the last item in your split array.



I hope it helps.






share|improve this answer





















  • Yes, it helps :) Thanks
    – Kima321
    Jul 18 '17 at 9:01



















0














String filename = "matches.csv";
File file = new File(filename);
try {
Scanner sc = new Scanner(file);
while (sc.hasNext()) {
String data = sc.next();
String values = data.split(",");
System.out.println(data);
}
sc.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}





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%2f45101192%2fhow-to-read-specific-columns-in-csv-file-java%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Completing your code:



    File file = new File("Filename.csv"); 
    List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
    for (String line : lines) {
    String array = line.split(";");
    System.out.println(array[0]+" "+array[array.length-1]);
    }


    You will notice that I changed the comma to a semi-colon as the split separator and added a bit to the println, which will be the last item in your split array.



    I hope it helps.






    share|improve this answer





















    • Yes, it helps :) Thanks
      – Kima321
      Jul 18 '17 at 9:01
















    0














    Completing your code:



    File file = new File("Filename.csv"); 
    List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
    for (String line : lines) {
    String array = line.split(";");
    System.out.println(array[0]+" "+array[array.length-1]);
    }


    You will notice that I changed the comma to a semi-colon as the split separator and added a bit to the println, which will be the last item in your split array.



    I hope it helps.






    share|improve this answer





















    • Yes, it helps :) Thanks
      – Kima321
      Jul 18 '17 at 9:01














    0












    0








    0






    Completing your code:



    File file = new File("Filename.csv"); 
    List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
    for (String line : lines) {
    String array = line.split(";");
    System.out.println(array[0]+" "+array[array.length-1]);
    }


    You will notice that I changed the comma to a semi-colon as the split separator and added a bit to the println, which will be the last item in your split array.



    I hope it helps.






    share|improve this answer












    Completing your code:



    File file = new File("Filename.csv"); 
    List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
    for (String line : lines) {
    String array = line.split(";");
    System.out.println(array[0]+" "+array[array.length-1]);
    }


    You will notice that I changed the comma to a semi-colon as the split separator and added a bit to the println, which will be the last item in your split array.



    I hope it helps.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jul 14 '17 at 11:52









    rlinden

    1,880812




    1,880812












    • Yes, it helps :) Thanks
      – Kima321
      Jul 18 '17 at 9:01


















    • Yes, it helps :) Thanks
      – Kima321
      Jul 18 '17 at 9:01
















    Yes, it helps :) Thanks
    – Kima321
    Jul 18 '17 at 9:01




    Yes, it helps :) Thanks
    – Kima321
    Jul 18 '17 at 9:01













    0














    String filename = "matches.csv";
    File file = new File(filename);
    try {
    Scanner sc = new Scanner(file);
    while (sc.hasNext()) {
    String data = sc.next();
    String values = data.split(",");
    System.out.println(data);
    }
    sc.close();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    }
    }





    share|improve this answer


























      0














      String filename = "matches.csv";
      File file = new File(filename);
      try {
      Scanner sc = new Scanner(file);
      while (sc.hasNext()) {
      String data = sc.next();
      String values = data.split(",");
      System.out.println(data);
      }
      sc.close();
      } catch (FileNotFoundException e) {
      e.printStackTrace();
      }
      }





      share|improve this answer
























        0












        0








        0






        String filename = "matches.csv";
        File file = new File(filename);
        try {
        Scanner sc = new Scanner(file);
        while (sc.hasNext()) {
        String data = sc.next();
        String values = data.split(",");
        System.out.println(data);
        }
        sc.close();
        } catch (FileNotFoundException e) {
        e.printStackTrace();
        }
        }





        share|improve this answer












        String filename = "matches.csv";
        File file = new File(filename);
        try {
        Scanner sc = new Scanner(file);
        while (sc.hasNext()) {
        String data = sc.next();
        String values = data.split(",");
        System.out.println(data);
        }
        sc.close();
        } catch (FileNotFoundException e) {
        e.printStackTrace();
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 11:51









        user10651772

        1




        1






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f45101192%2fhow-to-read-specific-columns-in-csv-file-java%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

            How to pass form data using jquery Ajax to insert data in database?

            National Museum of Racing and Hall of Fame

            Guess what letter conforming each word