list file number

Ads

 
 

Share on Google+Share on Google+

sumer
list file number
1 Answer(s)      8 years ago
Posted in : Java Beginners
Ads
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

Ads









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... have used counter here to detect the number of lines occurred in 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
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
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
Java get File List
Java get File List      ... the directory 'C:\\" to the constructor of class File.  file.listFiles...[]){  File file = new File("C:\\");    
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
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
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
Java file line count
Java file line count In the section, you will learn how to count the number... till the end of the file. We have used counter here to detect the number...("Number of Line: " + count); } } In this section, we have used data.txt file
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
buzz number
buzz number  buzz number
number sorting
number sorting  program to sort a list of numbers in descending order...(System.in); System.out.println("Enter List Elements: "); ArrayList<Integer> list=new ArrayList<Integer>(); for(int i=0;i<
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