Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes how to save an image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "how to save an image" Watch "how to save an image" New topic

how to save an image

Dinuka Arsakularatne
Ranch Hand

Joined: Aug 12, 2006
Posts: 198
hi everyone,

one small problem. can any one tell me how to save an image uploaded by a client in the server. say that the client clicks on a browse button and selects a file on his/her hard drive. how do we get that file and save it on the server?

thank you in advance

if who i am is what i have, and what i have is lost, then who am i?<br /> <br />SCJP 5.0<br />SCWCD 1.4<br />SCBCD preparing
Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

request.getInputstream() or request.getReader() and read the body contents. Then save them.

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Satish SN
Ranch Hand

Joined: Apr 19, 2005
Posts: 70
You can read the image from a web application using third party api provided by orielly
If you are using struts then it provides using which
you can read images/files in web application Google it for code using the above approaches.

Satish SN

Satish SN<br />SCJP 1.4 & SCWCD 1.4
Dinuka Arsakularatne
Ranch Hand

Joined: Aug 12, 2006
Posts: 198
ok, i know how to get the body content. but how do you save that file on your server. could some one provide a small piece of code or even a algo of how to save that file it would be really appreciated.

thank you
Kishore Balla
Ranch Hand

Joined: Jun 08, 2005
Posts: 165
File Upload

SCJP 5.0 : 88% My Story, SCWCD 1.4 : 94% My Story
subject: how to save an image