简体   繁体   中英

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). Note that the creator or assetInfo made a design mistake not exposing this information, OR you are trying to make one now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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