[Logo]
Forums Register Login
Get name of file from BufferedReader?

is there any method to find out the file name to which a BufferedReader is pointing to?
No. A BufferedReader may not even be associated with a File.
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.
Well, that's not possible if you only have the BufferedReader.
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).
 

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
instead of passing the BufferedReader, i have changed the method argument to the file name..that serves the purpose for now..
Well behaved women rarely make history - Eleanor Roosevelt. tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature


This thread has been viewed 2540 times.

All times above are in ranch (not your local) time.
The current ranch time is
Apr 22, 2018 04:49:24.