文件上传的秘密(二)向编码问题说再见
?
MultiPartFile multiPartFile = null;// determine the start position of content-type lineint pos = start = BoyerMoore.indexOf(buffer, _CTRF, end);// determine the line of content-typestart = BoyerMoore.indexOf(buffer, _CTRF, start + _CTRF.length);byte[] line = new byte[start - pos];System.arraycopy(buffer, end, line, 0, line.length);String contentType = new String(line);if (contentType.indexOf(_TEXT_CONTENT_TYPE_PREFIX) != -1) {multiPartFile = new MultiPartTextFile(dir + name, encoding);} else {multiPartFile = new MultiPartBinaryFile(dir + name);}multiPartFile.setStart(start + _CTRF.length * 2);return multiPartFile;?
好了,编码的问题就彻底解决了,程序中只要一次指定了编码字符集,就向乱码问题说再见。程序员是不是可以越来越"懒"了:)
?
<原创内容,版权所有,如若转载,请注明出处,不胜感谢!仪山湖>