从输入流获取文件名(Java) [英] Get filename from an inputstream (Java)

查看:5430
本文介绍了从输入流获取文件名(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);
    }


推荐答案

可以创建输入流从文件或任何其他数据源读取。因此,将文件名附加到输入流是没有意义的。查看 assetInfo 以查看该类是否公开该数据(您甚至可以使用反射查看该类)。请注意,创建者或 assetInfo 犯了设计错误而没有公开此信息,或者您正在尝试制作一个。

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.

这篇关于从输入流获取文件名(Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆