Get file name from FileReader object

Is there a way to get the file name (spc.f) given the FileReader object (f1)?

What good coding practice if you want to remember the file name for later use - save it on a different line?

FileReader f1 = new FileReader("spc.f"); buffread1 = new BufferedReader (f1 ); String name = f1.getName(); // <------ Does something like this exist ?? 
+4
source share
3 answers

Use the following code and using the java.io.File object, you can get the file name

 File file = new File("spc.f"); FileReader reader = new FileReader(file); file.getName(); 
+2
source

You cannot get the file name from the reader.

But you have the file name before. This way you can save it for further process. Something like that

  String file_name= "spc.f"; FileReader f1 = new FileReader(file_name); buffread1 = new BufferedReader (f1 ); String name = file_name; // 
+5
source

Save file_name in a separate String and select the place you want.

You cannot get the file_name object from FileReader .

+2
source

All Articles