Is there a way to get the file name from a FileOutputStream
or from FileInputStream
?
Field pathField = FileOutputStream. class. getDeclaredField("path"); pathField.
In Java, FileOutputStream is a bytes stream class that's used to handle raw binary data. To write the data to file, you have to convert the data into bytes and save it to file. See below full example. An updated JDK7 example, using new “try resource close” method to handle file easily.
To convert a file to byte array, ByteArrayOutputStream class is used. This class implements an output stream in which the data is written into a byte array. The buffer automatically grows as data is written to it. The data can be retrieved using toByteArray() and toString().
Looks like the answer is no:http://download.oracle.com/javase/1.4.2/docs/api/java/io/FileOutputStream.html
http://docs.oracle.com/javase/7/docs/api/index.html?java/io/FileOutputStream.html
There are no public methods that return the File
or String
used in construction of the stream.
EDIT: The same holds for FileInputStream
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With