@Test public void testGetNewUniqueName() { System.out.println("getNewUniqueName"); String pathToDir = "/src/test/testfiles/"; ArrayList<String> usedNames = new ArrayList<>(); File folder = new File(pathToDir); File[] listOfFiles = folder.listFiles(); if (listOfFiles != null) { for (File file : listOfFiles) { if (file.isFile()) { usedNames.add(file.getName()); } } } String result = FileLoader.getNewUniqueName(pathToDir); assert (result != null); usedNames.forEach((filename) -> { assert (!(filename.equals(result))); }); }
public static synchronized String getNewUniqueName(String pathToDir) { ArrayList<String> usedNames = new ArrayList<>(); File folder = new File(pathToDir.replace("\"", "")); File[] listOfFiles = folder.listFiles(); if (listOfFiles != null) { for (File file : listOfFiles) { if (file.isFile()) { usedNames.add(file.getName()); } } } String newName = getRandomName(100); while (usedNames.contains(newName)) { newName = getRandomName(100); } return newName; }
FileLoader { public static synchronized String getNewUniqueName(String pathToDir) { ArrayList<String> usedNames = new ArrayList<>(); File folder = new File(pathToDir.replace("\"", "")); File[] listOfFiles = folder.listFiles(); if (listOfFiles != null) { for (File file : listOfFiles) { if (file.isFile()) { usedNames.add(file.getName()); } } } String newName = getRandomName(100); while (usedNames.contains(newName)) { newName = getRandomName(100); } return newName; } }
FileLoader { public static synchronized String getNewUniqueName(String pathToDir) { ArrayList<String> usedNames = new ArrayList<>(); File folder = new File(pathToDir.replace("\"", "")); File[] listOfFiles = folder.listFiles(); if (listOfFiles != null) { for (File file : listOfFiles) { if (file.isFile()) { usedNames.add(file.getName()); } } } String newName = getRandomName(100); while (usedNames.contains(newName)) { newName = getRandomName(100); } return newName; } private  FileLoader(); }
FileLoader { public static synchronized String getNewUniqueName(String pathToDir) { ArrayList<String> usedNames = new ArrayList<>(); File folder = new File(pathToDir.replace("\"", "")); File[] listOfFiles = folder.listFiles(); if (listOfFiles != null) { for (File file : listOfFiles) { if (file.isFile()) { usedNames.add(file.getName()); } } } String newName = getRandomName(100); while (usedNames.contains(newName)) { newName = getRandomName(100); } return newName; } private  FileLoader(); static LinkedList<String> loadFileAsString(File file); static BufferedImage loadFileAsImage(File toRead); static synchronized String getNewUniqueName(String pathToDir); static List<String> listAllFilesFromFolder(String pathToDir, String endsWith); }
FileLoader { public static synchronized String getNewUniqueName(String pathToDir) { ArrayList<String> usedNames = new ArrayList<>(); File folder = new File(pathToDir.replace("\"", "")); File[] listOfFiles = folder.listFiles(); if (listOfFiles != null) { for (File file : listOfFiles) { if (file.isFile()) { usedNames.add(file.getName()); } } } String newName = getRandomName(100); while (usedNames.contains(newName)) { newName = getRandomName(100); } return newName; } private  FileLoader(); static LinkedList<String> loadFileAsString(File file); static BufferedImage loadFileAsImage(File toRead); static synchronized String getNewUniqueName(String pathToDir); static List<String> listAllFilesFromFolder(String pathToDir, String endsWith);  }