generatedReference将=" 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;
}
答案 0 :(得分:1)
CreateUniqueFileReference
生成这些数字。它就在代码中。
抱歉,错了,但看起来它是File.createTempFile()的输出,通常会在名称后面生成一长串数字,以使其唯一。