Get file name from input stream (Java)
•
Java
If I have this code, how can I keep the file name of the original file or reassign it to the new file?:
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,read); }
Solution
You can create an input stream to read from a file or any other data source Therefore, it makes no sense to append a file name to the input stream Check the assetinfo to see if the class exposes the data (you can even view the class using reflection) Please note that the creator or assetinfo will not disclose this information when the design is wrong, or you are trying to make one
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码