• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get name of file from BufferedReader?  RSS feed

 
thejwal pavithran
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

is there any method to find out the file name to which a BufferedReader is pointing to?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. A BufferedReader may not even be associated with a File.
 
thejwal pavithran
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay...actually i have written a method which operates on a file through a BUfferedReader passed to it as an argument..i wanted to print the file to which the BufferedReader was associated.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that's not possible if you only have the BufferedReader.
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like Steve said, a BufferedReader isn't necessarily wrapped around a FileReader or FileInputStream. It may be wrapped around a Socket's input stream, or even System.in (the last three with InputStreamReader in between).
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thejwal pavithran wrote:okay...actually i have written a method which operates on a file through a BUfferedReader passed to it as an argument..i wanted to print the file to which the BufferedReader was associated.

Then my suggestion would be to create a BufferedFileReader class of your own that extends BufferedReader, for all the reasons already mentioned.

Winston
 
thejwal pavithran
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
instead of passing the BufferedReader, i have changed the method argument to the file name..that serves the purpose for now..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!