可心利函数减少重复例如Random
例如得到的文件名为f.gif
Random r=new Random();
float f=r.nextFloat()*10000000;
String file=f+"f.gif"
这样重命名后的文件就不会重名了,试试就知道了。
例如得到的文件名为f.gif
Random r=new Random();
float f=r.nextFloat()*10000000;
String file=f+"f.gif"
这样重命名后的文件就不会重名了,试试就知道了。
int count=0;
// Initialization
mySmartUpload.initialize(pageContext);
// Upload
mySmartUpload.setTotalMaxFileSize(100000);
// set Upload MaxFileSize(100000);设置文件最大值
mySmartUpload.upload();
// Request
out.println("<STRONG>Display information about Requests</STRONG><BR>");
// Retreive Requests' names
//java.util.Enumeration e = mySmartUpload.getRequest().getParameterNames();
// Retreive parameters
String[] nid;
nid=mySmartUpload.getRequest().getParameterValues("id");
//getArray
String id=nid[0];
//getValue
out.println("getValue one's day...<BR>");
// Files Pic Upload
out.println("<BR><BR><STRONG>Display information about Files</STRONG><BR>");
try {
// Save the files with their original names in the virtual path "/upload"
// if it doesn't exist try to save in the physical path "/upload"
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
// Save it only if this file exists
if (!myFile.isMissing())
{
// Save the files with its original names in a virtual path of the web server
myFile.saveAs("d:\\tomcat\\webapps\\ROOT\\news\\pic\\" +id+"."+myFile.getFileExt());
//就在这里将文件另存!id 是名字,myFile.getFileExt()就是文件类型!!
// myFile.saveAs("/news/newsfile/newspic/" + myFile.getFileName(), mySmartUpload.SAVE_VIRTUAL);
// sample with a physical path
// myFile.saveAs("c:\\temp\\" + myFile.getFileName(), mySmartUpload.SAVE_PHYSICAL);
// Display the properties of the current file
out.println("FieldName = " + myFile.getFieldName() + "<BR>");
out.println("Size = " + myFile.getSize() + "<BR>");
out.println("FileName = " + myFile.getFileName() + "<BR>");
out.println("FileExt = " + myFile.getFileExt() + "<BR>");
out.println("FilePathName = " + myFile.getFilePathName() + "<BR>");
out.println("ContentType = " + myFile.getContentType() + "<BR>");
out.println("ContentDisp = " + myFile.getContentDisp() + "<BR>");
out.println("TypeMIME = " + myFile.getTypeMIME() + "<BR>");
out.println("SubTypeMIME = " + myFile.getSubTypeMIME() + "<BR>");
count ++;
// Save the files with their original names in the virtual path "/upload"
// count = mySmartUpload.save("/upload", mySmartUpload.SAVE_VIRTUAL);
}
// Display the number of files uploaded
out.println("<br>"+count + " file(s) uploaded.");
}
catch (Exception e)
{
out.println(e.toString());
}
out.println("上传成功!");
%>
"文件上传和文件中中文内容一起处理",你这名话是什么意思呀,不懂