Get file name from input stream (Java)

If I have this code, how can I save the file name of the source file or reassign it to a 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); } 
+6
source share
1 answer

An input stream can be created to be read from a file or from any other data source. Therefore, it makes no sense to attach the file name to the input stream. Take a look at assetInfo to see if this class provides this data (you can even look inside the class using reflection). Please note that the creator or assetInfo made a design error without exposing this information OR you are trying to do it now.

+12
source

Source: https://habr.com/ru/post/886553/


All Articles