Iterate over the Name Elements of a Path - Java File Path IO

Java examples for File Path IO:Path


Path class implements the Iterable interface, you can obtain an object that enables you to iterate over the elements in the path.

Demo Code

import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {

    public static void main(String[] args) {

        Path path = Paths.get("C:", "folder1/folder2/folder4", "test.txt");

        for (Path name : path) {
        }/*from w  ww  .  j a v  a2s .  c o  m*/


Related Tutorials