list file number

list file number

View Answers

April 16, 2009 at 5:40 PM

Hi friend,

Use the following code:

import java.io.*;

public class CreateFile{
public static void main(String[] args) throws IOException{
int countF=0,countD=0;
File f = new File( "C:\\" );
File[] listOfFiles = f.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
String text=listOfFiles[i].getName();
System.out.println(text);
countF++;
}
}
System.out.println("No. of Files : "+countF);
System.out.println();

for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isDirectory()) {
String dir=listOfFiles[i].getName();
countD++;
System.out.println(dir);
}
}

System.out.println("No. of Directories : "+countD);
}
}

Thanks









Related Tutorials/Questions & Answers:
list file number - Java Beginners
list file number  sir you still haven't understand my problem. i have to list out only the number of files in a given directory,your solution still give number of (files+directories) in given directory. are jfilechooser provide
line number in a file of entered string
line number in a file of entered string  when i entered string from console , it should show line number in a file of that string
Advertisements
Java file number of lines
Java file number of lines In this section, you will learn how to count the number of lines from the given file. Description of code: Java has provide... of the file. We have used counter here to detect the number of lines occurred
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program
java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program  
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program  
java.lang.UnsupportedClassVersionError: Bad version number in .class file
java.lang.UnsupportedClassVersionError: Bad version number in .class file...java.lang.UnsupportedClassVersionError: Bad version number in .class file  My java servlet not working correctly on my website. I have tried every
Map words to line number in text file and show occurence
Map words to line number in text file and show occurence  hi i want to Map words to line number in text file and show occurrence of word in java coding
How to rectify "Bad version number in .class file" exception in Eclipse
How to rectify "Bad version number in .class file" exception in Eclipse ... this request. exception javax.servlet.ServletException: Bad version number in .class file org.apache.jasper.servlet.JspServlet.service(JspServlet.java:274
Program to count the number of unique words in a file using HashMap
Program to count the number of unique words in a file using HashMap  ...[]) throws FileNotFoundException { File f = new File("C:/547647/word...()); System.out.println("The number of unique words: "+uniqueValues.size
putting words to line number form a java file/test file and show occurrence
putting words to line number form a java file/test file and show occurrence  hi all i want putting words to line number form a java file and show occurrence but i cant use mapping method i can only use the LinkedList
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.  Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.  Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.  Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.  Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples
ModuleNotFoundError: No module named 'cos_dumps_file_list'
ModuleNotFoundError: No module named 'cos_dumps_file_list'  Hi, My... named 'cos_dumps_file_list' How to remove the ModuleNotFoundError: No module named 'cos_dumps_file_list' error? Thanks   Hi
ModuleNotFoundError: No module named 'generate_nsis_file_list'
ModuleNotFoundError: No module named 'generate_nsis_file_list'  Hi...: No module named 'generate_nsis_file_list' How to remove the ModuleNotFoundError: No module named 'generate_nsis_file_list' error? Thanks   
Retrieve a list of words from a website and show a word count plus a specified number of most frequently occurring words
Retrieve a list of words from a website and show a word count plus a specified number of most frequently occurring words  I have to: 1.Retrieve...;String,Integer> object where the value is the number of occurrences of the word
Java get File List
Java get File List      ... the directory 'C:\\" to the constructor of class File.  file.listFiles...;void main(String args[]){  File file = new File("
Java file list()
Java file list() This section demonstrates you the use of method list(). You... listFiles() method or by list() method. Here we will discuss the method list() of File.... Then we have called the list( ) method through the File object. This method
JDOM Attribute Example, How to add a list of attribute at a xml file element.
JDOM Attribute Example, How to add a list of attribute to a xml file In this tutorial, we will see how to add a list of attribute to a xml file element... a list of attribute. By using Attrribute class we will create number of 
How to get of lastmodified file list between two times in java?
How to get of lastmodified file list between two times in java?  Hi, here is a code that list the last modified files in a directory between two... times like get the last modified file bet 02:00:00am and 01:00:00am (so
How to make a list from file text in J2ME - Java Beginners
How to make a list from file text in J2ME  I was trying to make a method that read file from text and make a list of it, I have tried ReadHelpText...) { } return null; } kamus.txt file contains: iconSebuah lambang kecil berupa gambar
Given a list, identify which are requirements for an EJB-jar file.
Given a list, identify which are requirements for an EJB-jar...;   Given a list, identify which are requirements for an EJB-jar file. The ejb-jar file MUST CONTAIN, either
buzz number
buzz number  buzz number
PHP SQL Number of Rows
PHP SQL Number of Rows      .... To understand how to count the number of rows in a table, we have created a sql_num_rows.php file. If you are not connected to the database, then create a connection
Count number of "*"
Count number of "*"  I have this code to count the number of * from a string entered. but I need to find it from an text file. Any idea? import...++; } } System.out.println("The number of vowels in the given sentence
prime number
prime number  get one number and check the number prime or not using if statement   Java Check Prime Number
the number of parameters
the number of parameters  How do I find out the number of parameters passed into function
Number in array
Number in array  How to write a program to check the number that we are entered from keyboard is in the given array
prime number
prime number  check prime number using if statement   Java Check Prime Number
prime number
prime number  check prime number using if statement   Java Check Prime Number
Java file line count
Java file line count In the section, you will learn how to count the number of lines from the given file. Description of code: Java has provide various... the number of lines occurred in the file.  hasNextLine(): This method
prime number
prime number  To check a number entered by user is prime or not?   Java check prime number import java.util.*; class CheckPrimeNumber { static boolean isPrime(int number){ boolean isPrime=false
prime number
prime number  could u pls help me out in finding whether a number is a prime number or not?   import java.util.*; class CheckPrimeNumber { static boolean isPrime(int number){ boolean isPrime=false
Count number of nodes
("\nThe number of nodes in a list are: %d\n",n); } Output... ) { printf("The data in the list are\n"); while (p!= NULL) { printf...; struct node *start = NULL ; printf("Enter number of nodes to be created
prime number
prime number  To check a number entered by user is prime
Armstrong number
Armstrong number  I want java program for Armstrong number
prime number
prime number  write a java program for prime number
prime number
prime number  to check wethere given number is prime or not?  ... { static boolean isPrime(int number){ boolean isPrime=false; int i=(int) Math.ceil(Math.sqrt(number)); while (i>1
prime number
prime number  HI!I want a java program that accepts a number from user and displays whether it is a prime number or not using BufferedReader
number sorting
number sorting  program to sort a list of numbers in descending order... input=new Scanner(System.in); System.out.println("Enter List Elements: "); ArrayList<Integer> list=new ArrayList<Integer>
Java count words from file
Java count words from file In this section, you will learn how to determine the number of words present in the file. Explanation: Java has provides several... by using the StringTokenizer class, we can easily count the number of words
Number Pyramid
Number Pyramid  Hi Everyone, Can someone help me write the code for the following number pyramid: print... 0 0 0 0 4 ... "); There is 5 spaces in between each number
random number
random number   Please How do I generate a program that gives me random integer from 115 to 250? Using java.util.random. Thank you very much!   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.util.
number pyramid
number pyramid   how to get the code for the following : 1 123 12345 1234567   class Pyramid{ public static void main(String args[]){ for(int i=1;i<=7
Primary number
Primary number  write a program to find the 100th or nth primary number?   import java.util.*; class PrimeNumber{ public static void main(String a[]) { Scanner input=new Scanner(System.in
Primary number
Primary number  write a program to find the 100th or nth primary number?   import java.util.*; class PrimeNumber{ public static void main(String a[]) { Scanner input=new Scanner(System.in
File
File  How to create .Exe file in jana

Ads