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 7818147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:28:52+00:00 2026-06-02T06:28:52+00:00

The code below reads from a file ‘helpFile.txt’ and checks for an index represented

  • 0

The code below reads from a file ‘helpFile.txt’ and checks for an index represented by ‘#’.
The variable read from the file is stored in the integer c and compared with ‘#’ if the read character is ‘#’ without casting the integer into character. I want to know if the comparison is valid as the compiler is not showing any error.
Also, suppose ‘#’ is found by the program in the file and a string called ‘topic’ immediately follows ‘#’ and it is read using readLine(). Will the ‘String info = br.readLine()’ be just ‘topic’ or ‘#’+’topic’?
Sorry for such a lengthy question. Help much appreciated.

boolean helpOn(String what){

    private BufferedReader br;
    private String info, topic;
    private static PrintWriter pw = new PrintWriter(System.out, true);
    int c;


        br = new BufferedReader(new FileReader("helpFile.txt"));

    try{
        do{
            //read characters until '#' is found
            c = br.read();


            if(***c=='#'***){   //check if the character is '#'
                pw.println(c);
                if((**topic=br.readLine()**).equalsIgnoreCase(what)){   //check if 'what' string is equal to 's' which is the string after '#'
                    while((info=br.readLine())!=null){  //print info until the end of info
                        if(info!=null)
                            pw.println(info);
                    }
                    return true;
                }
            }
        }
        while(c!=-1);
    }
    catch(IOException ex){
        pw.println("File error.");
        ex.printStackTrace();
        try{
            br.close();
        }
        catch(IOException e){
            pw.println("Error closing file.");
            e.printStackTrace();
        }
        return false;
    }

    try{
        br.close();
    }
    catch(IOException ex){
        pw.println("Error closing file.");
        ex.printStackTrace();
    }
    return false; //topic not found
}
  • 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-06-02T06:28:54+00:00Added an answer on June 2, 2026 at 6:28 am

    I tried your code, it is woking fine with me, i think u need to check your “helpFile.txt”. i used this in it.

    adad#hello

    howareyou

    and this is the outout i am getting.

    c: 35

    topic: hello

    info: howareyou

    i printed all the three vars u used. c, topic, info.
    Now since you are using readline() after reading a character, u must give your “info” from next line in “helpFile.txt”

    info will contain anything after topic, as you are using readline() function, it will go to the next line. try with my example.

    As soon as “#” is encountered, your var

    C will have “#” (35).

    then

    topic will have anything after the “#” till the end of line, because of readline();

    then

    info will have the next line after topic.

    If you format your helpFile.txt properly, this will work fine

    EDIT

    i have to specify the full file name everytime

    You are using eclipse, and you are saving the file in the “SRC” folder i guess. Save them in your Project folder. just one above the SRC folder and then do this.

    br = new BufferedReader(new FileReader("helpFile.txt"));
    

    it should work.

    EDIT2
    you don’t need to check info for null twice

    while((info=br.readLine())!=null){
    //print info until the end of
    //  if(info!=null) noT needed, u alreay did that above
    pw.println("info"+info);
                 }
    

    If it is NULL, it will automatically come out of loop.

    EDIT3

    i don’t want to print all the texts

    As you used # to mark the begining of the block, you could use anything to mark the end of it. eg

    helpFile.txt

    adad#hello

    howareyou

    $

    Other text here

    blah blah blah…

    …

    Now, you can modify your while as:

    while(!(info=br.readLine()).equals("$")){
          pw.println("info"+info);
                                }
    

    The loop will exit as soon as it gets “$”, and it won’t print anything after that.

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

Sidebar

Related Questions

I have my code below. It correctly reads my sqlite database file(that i have
Virtually every code example out there reads a TXT file line-by-line and stores it
EXPLANATION OF THE CODE BELOW: I am loading a .txt file and creating a
Below is the code I am using. It reads links from a textarea, and
I have used the code below to read rfid tag values. try { if
In the code below i`m trying to read a list of selected projects and
I use the below code to create and read my database in the app
In the below code, using (SqlDataReader dr = com.ExecuteReader(CommandBehavior.CloseConnection)) { while (dr.Read()) { _emailTemplate.EmailContent
Code below is used to save PostgreSql database backup from browser in Apache Mono
I am writing to file in android and read from the same file using

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.