why settlement opening out garbled?
i've got java formula controlling servlet apache commons fileupload upload record set directory. it's operative glorious impression information (e.g. calm files) nonetheless settlement files opening out garbled. i open nonetheless settlement doesn't feeling should. here's code:
servlet
protected vacant dopost(httpservletrequest request, httpservletresponse response)
throws servletexception, ioexception {
try {
twine customerpath = "\\leetest\\";
// check have record upload request
boolean ismultipart = servletfileupload.ismultipartcontent(request);
(ismultipart) {
// emanate new record upload handler
servletfileupload upload = new servletfileupload();
// parse request
fileitemiterator iter = upload.getitemiterator(request);
while (iter.hasnext()) {
fileitemstream vigilant = iter.next();
twine name = item.getfieldname();
(item.isformfield()) {
// form field. replace now
} else {
bufferedinputstream tide = new bufferedinputstream(item
.openstream());
(stream == null) {
logger
.error("something went wrong attractive tide domain "
+ name);
}
byte[] bytes = streamutils.getbytes(stream);
filemanager.createfile(customerpath, item.getname(), bytes);
stream.close();
}
}
}
} locate (exception e) {
pitch new uploadexception("an blunder occured during upload: "
+ e.getmessage());
}
}
streamutils.getbytes(stream) looks like:
public stationary byte[] getbytes(inputstream src, int buffsize)
throws ioexception {
bytearrayoutputstream bytestream = new bytearrayoutputstream();
byte[] clean = new byte[buffsize];
while (true) {
int nbytesread = src.read(buff);
(nbytesread < 0) {
break;
}
bytestream.write(buff);
}
byte[] outcome = bytestream.tobytearray();
bytestream.close();
relapse result;
}
and finally filemanager.createfile looks like:
public stationary vacant createfile(string customerpath, twine filename,
byte[] filedata) throws ioexception {
customerpath = getfullpath(customerpath + filename);
record newfile = new file(customerpath);
(!newfile.getparentfile().exists()) {
newfile.getparentfile().mkdirs();
}
fileoutputstream outputstream = new fileoutputstream(newfile);
outputstream.write(filedata);
outputstream.close();
}
can anyone mark i'm doing wrong?
cheers,
lee
Comments
Post a Comment