filename from java.io.FileInputStream

B

barry

Hi, a real quicky question.
Can I retrieve the filename from a FileInputStream?

private String getFilename(FileInputStream fis)
{
return "test.dat"; //test.dat hard-coded
}


fis has been created by

FileInputStream fis=new FileInputStream(new File("c:\\test.dat"));

but I want getFilename(..) to work with any filename, not just test.dat.

Thank you
Barry
 
C

Christophe Vanfleteren

barry said:
Hi, a real quicky question.
Can I retrieve the filename from a FileInputStream?

private String getFilename(FileInputStream fis)
{
return "test.dat"; //test.dat hard-coded
}


fis has been created by

FileInputStream fis=new FileInputStream(new File("c:\\test.dat"));

but I want getFilename(..) to work with any filename, not just test.dat.

Thank you
Barry

You can't. But you could create your own subclass of FileInputStream, where
you do keep the filename available.

Or you could create a Map, using the FileInputStream as key, and the
filename as value.
 
A

Andrew Hobbs

barry said:
Hi, a real quicky question.
Can I retrieve the filename from a FileInputStream?

private String getFilename(FileInputStream fis)
{
return "test.dat"; //test.dat hard-coded
}


fis has been created by

FileInputStream fis=new FileInputStream(new File("c:\\test.dat"));

but I want getFilename(..) to work with any filename, not just test.dat.

Thank you
Barry

I don't think you can. However since you need the path/filename in the
first place to construct the FileInputStream why do you want to re-extract
it. At the very least, as long as you still have a reference to the File
then you can get the information you want from that.

Andrew


--
********************************************************
Andrew Hobbs PhD

MetaSense Pty Ltd - www.metasense.com.au
12 Ashover Grove
Carine W.A.
Australia 6020

61 8 9246 2026
metasens AntiSpam @iinet dot net dot au


*********************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top