Is there a way to obtain the file name (spc.f), given a FileReader object (f1)?
Whats a good coding practice if you want to remember the file name for later use - store it in another string ?
FileReader f1 = new FileReader("spc.f");
buffread1 = new BufferedReader (f1 );
String name = f1.getName(); // <------ Does something like this exist ??
You cannot get file name from a reader object.
But you have file name just before.So you can store it for further process. Something like this
String file_name= "spc.f";
FileReader f1 = new FileReader(file_name);
buffread1 = new BufferedReader (f1 );
String name = file_name; //
Use the following code and using the java.io.File object you can retrieve the file name
File file = new File("spc.f");
FileReader reader = new FileReader(file);
file.getName();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With