generatedReference will = "abc" (例如) nameWithExt = "abc.txt"
但是保存到文件系统的文件最终会是:abc501883476493193605.txt
这些数字似乎是由 smoething 随机生成的?有人知道发生了什么吗?
File directory = new File(bc.getUploadDirectoryPath(dir)); //c:/temp
String generatedReference = CreateUniqueFileReference();
String nameWithExt = generatedReference + "." + GetExtensionOfFile(fb.getFileName());
//File f = File.createTempFile(generatedReference, "." + GetExtensionOfFile(fb.getFileName()), directory);
//File f = File.createTempFile("abc","myExt", directory); STILL GENERATED RANDOM NOS in file?
fb.save(f);
bc.getLogger().info("TrySaveFile: "+nameWithExt);
public static String CreateUniqueFileReference() {
java.util.Date today = new java.util.Date();
String d = new java.text.SimpleDateFormat("ddMMyyyyHHmmss").format(new java.sql.Timestamp(today.getTime()));
Random r = new Random();
String randomNum = Integer.toString(r.nextInt(10000) + 0);
return d + "_" + randomNum;
}