Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How do I skip the ''header'' (first line) in BufferedReader?

  1. #1
    Junior Member
    Join Date
    Apr 2022
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default How do I skip the ''header'' (first line) in BufferedReader?

    I need to skip my very first line from the txt file, but I can't seem to find any solution to this as I only want my team names

    My file is currently:

    teamName, teamPlayers
    teamA, 1, 2, 3, 4
    teamB, 1, 2, 3, 4

    AND can I count the lines? So in another method it can go on if it has three lines (to teams)?

        public static void readGameData() {
     
            String path = "src/teamData.txt";
            String teamNamesFile = "";
     
            try{
                BufferedReader br = new BufferedReader(new FileReader(path));
                while((teamNamesFile = br.readLine()) != null){
                    String [] teamNames = teamNamesFile.split(",");
                    if(teamNamesFile.equals ("teamName");
                    System.out.println("This is from file :" + teamNames[0]);
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

  2. #2
    Junior Member
    Join Date
    Oct 2022
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do I skip the ''header'' (first line) in BufferedReader?

    The process of coding requires understanding the various aspects of computer programming, allowing a person to translate their requirements into an executable program https://mlsdev.com. It also requires analysis, conceptualization, and testing. While programming may seem like an intimidating endeavor, it doesn't have to be. You can use simple text editors to do the work, while more advanced programs can help you create more sophisticated software.
    Last edited by mikesponer; October 16th, 2022 at 05:09 AM.

Similar Threads

  1. Re: Problem with BufferedReader : readLine() cut the line
    By caveden in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 10th, 2012, 08:46 AM
  2. Problem with BufferedReader : readLine() cut the line
    By mfgagne73 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 3rd, 2012, 10:18 AM
  3. Problem with Reading very long line using bufferedReader
    By nicool in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: November 7th, 2011, 01:32 PM
  4. How to Read a file line by line using BufferedReader?
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM
  5. How to Read a file line by line using BufferedReader?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM