File path/name from InputStream

前端 未结 3 2089
野性不改
野性不改 2020-12-18 21:56

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

3条回答
  •  庸人自扰
    2020-12-18 22:09

    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);
        }
    

提交回复
热议问题