Read File in String Using Java BufferedInputStream Example

Want to learn quickly?
Try one of the many quizzes. More than Java 400 questions with detailed answers.


  • In a test result are declared as follows
    if % marks >=80 then the result declared is “PASSED WITH STAR”
    if %marks <80 but >=60 then the candidate is awarded “FIRST DIVISION”
    if %marks <60 but >=40 then the candidate is awarded “SECOND DIVISION”
    if % marks <40 then the result is declaredas “FAILED”
    write a program in java to input the %marks and print the result

    • [code]
      import java.io.*;
      class Marks
      double percentage;
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      void main()throws IOException
      System.out.print(“Enter Percentage Marks:”);
      System.out.println(“PASSED WITH STAR”);
      else if(percentage<80 || >=60)
      System.out.println(“FIRST DIVISION”);
      else if(percentage<60 || >=40)
      System.out.println(“SECOND DIVISION”);
      else if(percentage<40)
      System.out.println(“ENTER CORRECT PERCENT MARKS”);


      • too small a requiremend for using buffers !!
        for reading a single mark at a time and writing on screen not neccesary to read using buffers

        am not sure how are you taking input or are you reading from the user input
        wanted to now if reading from file and commenting there

      • How can i read this variable in other method? for example i wrote a method which reads the file in to a variable. Now i want use the variable in other methods to search the text file for different values.

  • Create a class it has following data members:-
    -account id
    initialize the data members through constructors & define a print function & also define a function to compare names. It returns true if the name is equal or else returns false. Initialize an array of objects. Pass a name from the
    command line & search for the name in the array of objects , if it is existing print the information of the object.


Facebook Fans