从输入流获取文件名 (Java)
如果我有这段代码,我如何保留原始文件的文件名或将其重新分配给新文件?:
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);
}
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以创建输入流以从文件或任何其他数据源读取。因此,将文件名附加到输入流是没有意义的。查看 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 orassetInfo
made a design mistake not exposing this information, OR you are trying to make one now.