File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes File upload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "File upload" Watch "File upload" New topic

File upload

riz shahid

Joined: Feb 02, 2011
Posts: 2
this code is not working.
try {
FileItemFactory factory=new DiskFileItemFactory();
ServletFileUpload upload=new ServletFileUpload(factory);
String location="D:\tem";
File saveto=new File(location);

DiskFileItemFactory factorys=new DiskFileItemFactory();
FileItem items=null;
factorys.createItem(items.getFieldName(), items.getContentType(), false,"field1");
DiskFileItem fi=new DiskFileItem("field1", items.getContentType(), false, "mypic.png", 10000, saveto);
//MultipartFile f = new CommonsMultipartFile(fi);

} catch (Exception e1) {
// TODO Auto-generated catch block
Sreelatha Sankaranarayanan

Joined: Dec 10, 2010
Posts: 9

Here you have assigned items = null and in the next line you are doing items.getFieldName() , which will result in NullPointerException, you will need to initialize items before doing any operations on it.
riz shahid

Joined: Feb 02, 2011
Posts: 2
you are right but i think fileitem save the value in binary format in any other file as like text etc but i want to save file as like image etc on my system after getting from user you have any idea about this how i can do this?
I agree. Here's the link:
subject: File upload
It's not a secret anymore!