How to convert byte array to File in Java?
byte[] objFileBytes, File objFile
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A File object doesn’t contain the content of the file. It is only a pointer to the file on your hard drive (or other storage medium, like an SSD, USB drive, network share). So I think what you want is writing it to the hard drive.
You have to write the file using some classes in the Java API
You can also use a Writer instead of an OutputStream. Using a writer will allow you to write text (String, char[]).
Since you said you wanted to keep everything in memory and don’t want to write anything, you might try to use
ByteArrayInputStream. This simulates an InputStream, which you can pass to the most of the classes.