Slip 8 - B) Write a java program to display the files having extension .txt from a given directory.

 Solution: 

import java.io.File;
class Slip8B {
    public static void main(String[] args) {
        File file = new File(" Your File Path ");
        String[] fileList = file.list();
        for(String str : fileList) {
            if(str.endsWith(".txt")){
                System.out.println(str);
            }
        }
    }
}

Output:

Output_pic


Post a Comment

0 Comments