subysri
asked on
Uploading a file
I need to store a file in database. How can I do this using java?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please proceed with that recommendation.
Well, the main problem was to know how to insert the data - not about performance, I guess.
It's not a performance issue - it's about a potentially fatal memory problem. The approach i suggested doesn't suffer from this drawback
Well - memory problems may or may not come. That's about optimizing your approach - the difference between "how to do it" and "how to do it best". I agree that your method is more efficient, but I assumed that this one only asks "how to do it" because it said nothing else ;-) So I didn't go into the details. The questioner should have responded if he faced memory problems, too.... anyways, I would be glad with a split.
>>The questioner should have responded if he faced memory problems,
That error may well occur only rarely, and may well be quite difficult to debug
That error may well occur only rarely, and may well be quite difficult to debug
Yes, and yes ;-)
Please proceed with that recommendation.
File f = new File ( "filename" ) ;
FileInputStream fis = new FileInputStream ( f ) ; // or new FileInputStream ( "filename" ) ;
byte[] array = new byte[f.length ()] ;
fis.read ( array ) ;