commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j m <nospamtomeple...@gmail.com>
Subject file upload inserts additional chars into file
Date Fri, 16 Sep 2005 17:46:55 GMT
Hi all,

I'd like to upload a plain ascii file from within my portlet. The file
is relatively small - about 87kB an contains about 6000 lines.

After the file is uploaded (there are no Exeptions thrown) the file contains 
a sequence of many (about 250) char c = 0 (zero) characters after line
228 of the uploaded file. I have checked that with a hex editor.

But after this sequence the file contains again the correct rest of
the uploaded file till
the last line - so no timeout or anything.

When I write the string of the FileItem to System.out here also
everything apperas correct - but I assume only because char c = 0 is
not displayed.

here is the code I' using. 

= cut ====================================================== 
DiskFileItemFactory factory = new DiskFileItemFactory();
PortletFileUpload upload = new PortletFileUpload(factory);
try {
	List fileItems = upload.parseRequest((ActionRequest)request); 
				
	Iterator iter = fileItems.iterator();
	while (iter.hasNext()) {
		FileItem item = (FileItem) iter.next();
		if (item.isFormField()) {
	        	//processFormField(item);
		} else {
			//processUploadedFile(item);
				
			File uploadFile = new File(UPLOAD_DIR + File.separator + UPLOAD_FILE_NAME);
			uploadFile.createNewFile();
	
			// Solution 1 which does not work correctly
			// item.write(uploadFile);
		
			// Solution 2 which does not work correctly
			// source: http://www.javapractices.com/Topic42.cjp
			Writer output = null;
			try {
			output = new BufferedWriter( new FileWriter( uploadFile));
			output.write( item.getString());
			} finally {
				if (output != null) output.close();
			}
		}
	}
} catch (FileUploadException e) {
	e.printStackTrace();
} catch (Exception e) {
	e.printStackTrace();
}

= cut ====================================================== 

thanks in advance
jm

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message