views:

305

answers:

3

How to obtain File Path/Name from an InputStream in Java ?

+1  A: 

You cannot get that information through any documented API.

bmargulies
+2  A: 

You can't because the InputStream might not have been a file or path. You can implement your own InputStream that generates data on the fly

Pyrolistical
+1  A: 

It's not possible. (not from the FileInputStream in the Java API). The FileInputStream constructor does not store this information in any field:

public FileInputStream(File file) throws FileNotFoundException {
    String name = (file != null ? file.getPath() : null);
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkRead(name);
    }
        if (name == null) {
            throw new NullPointerException();
        }
    fd = new FileDescriptor();
    open(name);
    }
Bruno Rothgiesser