Sunday, 4 February 2018

Java Program to count and name files inside a directory

package fileCountAndName;

import java.io.File;

import java.io.IOException;
public class fileCountAndName {

public static void main(String[] argv) throws IOException {
File folder = new File("C:\\Users\\Desktop\\Files\\");

File[] listOfFiles = folder.listFiles(); int count=0;

System.out.println("File Inside the folder are");

for (int i = 0; i < listOfFiles.length; i++)

{
if (listOfFiles[i].isFile())

{

count++;

File f = new File("C:\\Users\\Desktop\\Files\\"+listOfFiles[i].getName()); System.out.println(f.getName());

}

}

System.out.println("Total number of files are :"+count);
}

}

No comments:

Post a Comment

Handaling XLS File In Java

This code will help you to handle xls file in java using apache poi. package test; import java.io.File; import java.io.FileInputStream...