简体   繁体   English

从输入流获取文件名(Java)

[英]Get filename from an inputstream (Java)

if I have this code, how could I keep the filename of the original file or reassign it to the new one?: 如果我有这个代码,我怎么能保留原始文件的文件名或重新分配给新文件?:

    InputStream input= assetInfo.openStream();
    File t = new File("");

    OutputStream out = new FileOutputStream(t);

    int read=0;
    byte[] bytes = new byte[1024];

    while((read = input.read(bytes))!= -1){
        out.write(bytes, 0, read);
    }

An input stream can be created to read from a file or from any other source of data. 可以创建输入流以从文件或任何其他数据源读取。 Therefore it makes no sense to have a filename attached to an input stream. 因此,将文件名附加到输入流是没有意义的。 Look in assetInfo to see if that class exposes that data (you can even look inside the class using reflection). 查看assetInfo以查看该类是否公开该数据(您甚至可以使用反射查看该类)。 Note that the creator or assetInfo made a design mistake not exposing this information, OR you are trying to make one now. 请注意,创建者或assetInfo在设计错误时不会泄露此信息,或者您正在尝试制作一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM