Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7073431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:55:44+00:00 2026-05-28T05:55:44+00:00

I have a text file in my computer which I am reading form my

  • 0

I have a text file in my computer which I am reading form my java program, I want to build some criteria. Here is my Notepad File :

   #Students
   #studentId   studentkey  yearLevel   studentName token   
   358314           432731243   12          Adrian      Afg56       
   358297           432730131   12          Armstrong   YUY89       
   358341           432737489   12          Atkins      JK671   

        #Teachers
        #teacherId  teacherkey    yearLevel teacherName token   
        358314          432731243   12          Adrian      N7ACD       
        358297          432730131   12          Armstrong   EY2C        
        358341          432737489   12          Atkins      F4NGH

when I read from this note pad file, I get the exact data as it is in my application
but I want to read only the token column inside students and put them in my array named
studentTokens. Here is the code

public static void main(String[] args) {
    ArrayList<String > studentTokens = new ArrayList<String>();

    try{
        // Open the file that is the first 
        // command line parameter
        FileInputStream fstream = new  FileInputStream("c:/work/data1.txt");

        // Get the object of DataInputStream
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;

        //Read File Line By Line
        while ((strLine = br.readLine()) != null)   {
            // Print the content on the console
            System.out.println (strLine);
        }

        //Close the input stream
        in.close();
    }catch (Exception e){//Catch exception if any
        System.err.println("Error: " + e.getMessage());
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:55:45+00:00Added an answer on May 28, 2026 at 5:55 am

    A short tip:

    private static Integer STUDENT_ID_COLUMN = 0;
    private static Integer STUDENT_KEY_COLUMN = 1;
    private static Integer YEAR_LEVEL_COLUMN = 2;
    private static Integer STUDENT_NAME_COLUMN = 3;
    private static Integer TOKEN_COLUMN = 4;
    
    public static void main(String[] args) {
    
        ArrayList<String> studentTokens = new ArrayList<>();
    
        try (FileInputStream fstream = new FileInputStream("test.txt");
              InputStreamReader inputStreamReader = new InputStreamReader(fstream);
              BufferedReader br = new BufferedReader(inputStreamReader)) {
    
            String strLine;
    
            // Read File Line By Line
            while ((strLine = br.readLine()) != null) {
    
                strLine = strLine.trim();
    
                if ((strLine.length() != 0) && (strLine.charAt(0) != '#')) {
                    String[] columns = strLine.split("\\s+");
                    studentTokens.add(columns[TOKEN_COLUMN]);
                }
    
            }
        }
        catch (Exception e) {// Catch exception if any
            System.err.println("Error: " + e.getMessage());
            return;
        }
    
        for (String s : studentTokens) {
            System.out.println(s);
        }
    }
    

    The above code is not complete solution. It extracts all tokens (for students and teachers). I hope you’ll manage to make it work just for student tokens from there on…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file in my computer which i am reading form my
So I am reading from a text file which has product information I have
I have text file with some stuff that i would like to put into
I have text file with some text information and i need to split this
I have a html file which select images from user's computer.code is given bellow
I have a problem here which i am trying to solve. The program is
I have a html file which select images from user's computer.code is given bellow
I am fairly new to php. I have a text file on my computer
Hi just looking for some direction, I have a HTML form which has several
I have a jquery-ui-dialog that contains a <form> which contains a <input type=file >

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.