Android New Image has strange numbers on the end of the file name

后端 未结 2 1141
闹比i
闹比i 2021-01-19 16:07

I\'m writing a camera2 app in android and when I try to save the image, something adds extra numbers on the end of the filename before the \'.jpg\'

I have a feeling

2条回答
  •  独厮守ぢ
    2021-01-19 16:20

    According implementation of used method new file is created with extra random integer new File(tmpDirFile, prefix + Math.randomIntInternal() + suffix)

    public static File createTempFile(String prefix, String suffix, File directory)
                throws IOException {
            // Force a prefix null check first
            if (prefix.length() < 3) {
                throw new IllegalArgumentException("prefix must be at least 3 characters");
            }
            if (suffix == null) {
                suffix = ".tmp";
            }
            File tmpDirFile = directory;
            if (tmpDirFile == null) {
                String tmpDir = System.getProperty("java.io.tmpdir", ".");
                tmpDirFile = new File(tmpDir);
            }
            File result;
            do {
                result = new File(tmpDirFile, prefix + Math.randomIntInternal() + suffix);
            } while (!result.createNewFile());
            return result;
        }
    

提交回复
热议问题