Last active
April 12, 2016 13:31
-
-
Save legap/0e8eb2b550ecd6d533576a5e59bb9657 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.FileFilter; | |
import java.nio.file.DirectoryStream; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
public class JavaFileOperations { | |
public void findAllXmlFilesInFolderWithJavaIO() { | |
String myPath = "your/path/goes/here"; | |
File folder = new File(myPath); | |
FileFilter fileFilter = pathname -> pathname.isFile() && pathname.getName().endsWith(".xml"); | |
File[] xmlFiles = folder.listFiles(fileFilter); | |
for (int i = 0; i < xmlFiles.length; i++) { | |
System.out.println(xmlFiles[i].getAbsoluteFile()); | |
} | |
} | |
// FIXME filter for xml files only | |
public void findAllFilesInFolderWithJavaNIO() throws Exception { | |
Path myPath = Paths.get("your/path/goes/here"); | |
DirectoryStream<Path> stream = Files.newDirectoryStream(myPath); | |
for (Path entry : stream) { | |
System.out.println(entry.getFileName()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment