Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get file name from FileOutputStream

Is there a way to get the file name from a FileOutputStream or from FileInputStream?

like image 479
Ebbu Abraham Avatar asked Feb 08 '11 06:02

Ebbu Abraham


People also ask

How do I get file name from FileOutputStream?

Field pathField = FileOutputStream. class. getDeclaredField("path"); pathField.

How do I convert FileOutputStream to a file?

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.

How do I get bytes from FileOutputStream?

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().


1 Answers

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.

like image 103
Thorn G Avatar answered Sep 25 '22 12:09

Thorn G