-2

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;
    }
4

1 回答 1

1

The CreateUniqueFileReference generates those numbers. It's right there in the code.

Sorry, was wrong, but it looks like it's the output from File.createTempFile(), that typically generates a long string of numbers after the name to make it unique.

于 2012-05-03T03:35:12.877 回答