This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Java in General and the fly likes Problem in file uploading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem in file uploading" Watch "Problem in file uploading" New topic

Problem in file uploading

Preethinj Math

Joined: Mar 07, 2006
Posts: 10

I am uploading a file into D drive,once I uploaded a file,for the 2nd time I checking a condition, whether that file exists in that directory or not?

If it does not ,then upload the file.If it exists then display a message saying "The file already exists".

My problem is when I try to upload the existing file,it does not go through the while loop at all!,so I am not able to catch the filename.

I am pasting the pieces of code.

need help please.....


MultiPartRequest multi = new MultiPartRequest(req,myBu.SERVERROOT+"/jsp/projects/share",5*1024*1024);
// System.out.println("After request");
out.println("<head><title>Documents Upload...</title></head>");
out.println("<body bgcolor='#BBD7EC'>");
out.println("<h1><font color='#D02020' face='Verdana' size='4pt' ><strong>Documents Uploading...</strong></font></h1>");

out.println("<h3>The Following Document has been Uploaded successfully<h3>");
out.println("<pre align='center'>");

Enumeration files = multi.getFileNames();
String name = (String)files.nextElement();
String filename = multi.getFilesystemName(name);
System.out.println("filename is "+ filename);
docName = filename;
String type = multi.getContentType(name);
File f = multi.getFile(name);
//out.println("name: "+name);
out.println("<font color='#000099' face='Verdana' size='2pt' ><strong>");
out.println("Document Name : "+filename);
System.out.println("docName in Servlet :" + docName + ", fileName :" + filename + "with quotes : " + "\"" + docName + "\"" );
out.println("Document Type : "+type);

if(f != null){
out.println("Document Size : "+f.length() +" (bytes)");
doDML = "YES";
catch(Exception e){
doDML = "NO";


System.out.println("<body bgcolor='#BBD7EC'>");
System.out.println("<pre align='center'>");
System.out.println("<h2><strong>File already exists</strong></h2>");//added by preethi to test
return true;
readAndSaveFile(in, boundary,fileName);
if (fileName.equals("unknown")){
files.put(name, new UploadedFile(null, null, null));

files.put(name, new UploadedFile(dir.toString(),fileName, ContentType));
}//end of flag loop
return false;
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24190

Do not post the same question to multiple forums; instead, Carefully Choose One Forum. I deleted the other copy of this thread.

[Jess in Action][AskingGoodQuestions]
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Problem in file uploading
It's not a secret anymore!