肯定是你的servlet有问题,我的上传中文文件没问题, 我是这样做的:in = new DataInputStream(request.getInputStream()); //get length of content data int formDataLength = request.getContentLength(); //allocate a byte array to store content data byte dataBytes[] = new byte[formDataLength]; //read file into byte array int bytesRead = 0; int totalBytesRead = 0; int sizeCheck = 0; while (totalBytesRead < formDataLength) { //check for maximum file size violation sizeCheck = totalBytesRead + in.available(); if (sizeCheck > MAX_SIZE) { out.println("Sorry, file is too large to upload."); return; } bytesRead = in.read(dataBytes, totalBytesRead, formDataLength); totalBytesRead += bytesRead; } //create string from byte array for easy manipulation String file = new String(dataBytes); //这里得到文件名 String saveFile = file.substring(file.indexOf("filename=\"")+10);
我是这样做的:in = new DataInputStream(request.getInputStream());
//get length of content data
int formDataLength = request.getContentLength();
//allocate a byte array to store content data
byte dataBytes[] = new byte[formDataLength];
//read file into byte array
int bytesRead = 0;
int totalBytesRead = 0;
int sizeCheck = 0;
while (totalBytesRead < formDataLength)
{
//check for maximum file size violation
sizeCheck = totalBytesRead + in.available();
if (sizeCheck > MAX_SIZE)
{
out.println("Sorry, file is too large to upload.");
return;
}
bytesRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += bytesRead;
}
//create string from byte array for easy manipulation
String file = new String(dataBytes); //这里得到文件名
String saveFile = file.substring(file.indexOf("filename=\"")+10);