Convert File[] to String[] in Java
You don't need to convert the whole array. Just call File
's getAbsolutePath()
method:
driver.findElement(By.id(id1)).sendKeys(listOfFiles[1].getAbsolutePath());
But if you do want to convert the whole array, here is the Java 8 way to do this (simplified by @RemigiusStalder):
String listOfPaths[] = Arrays.stream(listOfFiles).map(File::getAbsolutePath) .toArray(String[]::new);