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

Java examples for File Path IO:Path

Introduction

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) {
            System.out.println(name);
        }/*from  w w w  .j  a v  a  2 s.co m*/
    }
}

Result


Related Tutorials