Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Abt Buffered readers  RSS feed

 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can same BufferedrReader instance be used several times in a program to scan different inputs...........sometimes character- sometimes string may be ?

i mean say...for e.g i create one instance of bufferedReader say..."br"
i use for the first time br to scan input from user but now....later in program i again feel need....to scan another input from user....now can i again use br which was now, pointing to previous input ?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can allocate a new BufferedReader object, and use the same variable "br" to point to it; although generally, what you're describing is bad style. Using one variable for different purposes at different times makes code hard to understand.

Unless you put the reading code into a method which accepts a BufferedReader as a parameter; then you can use that one routine to read from many different sources.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!