Avatar of exroopan
exroopan

asked on 

How do I read a java.io.BufferedReader twice

What I wish to do is to read the BufferedReader twice.
After reading the first time I try to reset it but I couldn't.
see my code down :

InputStreamReader re = new InputStreamReader(urlConnection.getInputStream());
	     
BufferedReader in = new BufferedReader(re);
StringBuffer sbuf = new StringBuffer();
String inputLine;
            
   while ((inputLine = in.readLine()) != null) {
               System.out.println(inputLine);
               sbuf.append(inputLine);
   }
   in.reset();
    
    while ((inputLine = in.readLine()) != null) {
               System.out.println(inputLine);
                sbuf.append(inputLine);
     }

Open in new window

JavaProgrammingProgramming Languages-Other

Avatar of undefined
Last Comment
CEHJ
Avatar of Mick Barry
Mick Barry
Flag of Australia image

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo