public static File createRandomFile(File dir, String ext) {
        if (!dir.isDirectory()) return null;
        File[] files = dir.listFiles();

        while (true) {
            String fileName = String.valueOf((int) (Math.random() * 1e10)) + '.' + ext;
            boolean found = false;

            if (files != null) {
                for (File file : files) {
                    if (file.getName().equals(fileName)) {
                        found = true;
                        break;
                    }
                }
            }

            if (!found) return new File(dir, fileName);
        }
    }