This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Byte[] to File without saving on disk Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Byte[] to File without saving on disk" Watch "Byte[] to File without saving on disk" New topic
Author

Byte[] to File without saving on disk

Juan Manuel Diaz
Ranch Hand

Joined: Mar 23, 2009
Posts: 53
Hi fellows!!, how are you?, i have been developing an applet to digitally sign PDF files, the applet gets those files from a php page, sign the files and last send each signed file to another php page for saving them in a data base. The problem is in the uploadSignedFile method, this method sends the signed file, receives one parameter, a byte[] with the signed bytes and it must to convert it into a File for send it across the HTTP post protocol. Everything works fine, but when I create the FileOutputStream, a new file appears in my desktop (only in IE7, not with Firefox, I think that is a permissions difference) . I dont want new files on the client disk and they too!, How can I do to manage the File only in memory without saving them in the client disk?

Best Regards,
Juan M. Diaz
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

When you create a FileOutputStream it will always create a file on disk if it doesn't exist yet. That's simply what it does. If you want to avoid this you should ask yourself if you really need File, and cannot send the byte[] directly, or send from an InputStream instead. If that's possible you can use a ByteArrayInputStream around the byte[].


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Juan Manuel Diaz
Ranch Hand

Joined: Mar 23, 2009
Posts: 53
Hi!, thanks for the quickly answer... I really need File, because the implementation of HTTP Post needs File... If i send the byte[] directly, the php page that receives the files dont work. Is any chance to use File in memory?

Regards,
JM Diaz
Juan Manuel Diaz
Ranch Hand

Joined: Mar 23, 2009
Posts: 53
Solved. I found a method that spec an InputStream as argument. I use ByteArrayInputStream.

Thanks,
JM Diaz
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Byte[] to File without saving on disk
 
Similar Threads
Send file to applet from PHP
Add Exception-[ Is this the only way?]
Uploading files from an applet to a servlet!?!?
Trying to emulate HTTP file upload with an applet
How send byte stream? (Instead of pointing to file)