Question

generatedReference will = "abc" (for example) nameWithExt = "abc.txt"

But the file saved to the filesystem will end up being: abc501883476493193605.txt

Where those numbers seem to be randomly generated by smoething? Anyone konw whats going on?

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;
    }
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top