File name from file descriptor

Posted on 2003-10-31
Last Modified: 2008-03-06
Can I get the file name from  file descriptor using reflection.

Question by:shankii
LVL 16

Expert Comment

ID: 9659842
What do you mean by a "file descriptor" exactly?

Certainly a File object has a method (getName) which returns its name.
LVL 15

Expert Comment

ID: 9660951
Do you mean

From the javadoc:

"Applications should not create their own file descriptors."

If you mean, can you get the name of a .class file that contains the code you are examining by reflection, then get the name of the Constructor and add ".class" to it.
LVL 92

Accepted Solution

objects earned 250 total points
ID: 9661403
You can't.
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

LVL 15

Expert Comment

ID: 9661463
Hi objects,

   I was trying not to be so blunt with my first point ;-)

Author Comment

ID: 9661477
What I meant is :

  FileInputStream fis = new FileInputStream(filename);
  fileDescriptor fd = fis.getFD();

 I want to get the file name from this fd.

LVL 92

Expert Comment

ID: 9661479
I know what you meant :)  The FileDescriptor instance knows nothing about the name of the file
LVL 15

Expert Comment

ID: 9661489
Why would you want to do that?  Why not just store filename?

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question