Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain file name from FileReader object

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 ?? 
like image 957
Nikhil Avatar asked Sep 24 '13 05:09

Nikhil


2 Answers

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;   //   
like image 155
Suresh Atta Avatar answered Oct 12 '22 23:10

Suresh Atta


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();
like image 35
Wenod Pathirana Avatar answered Oct 12 '22 23:10

Wenod Pathirana