Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners list file number
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sumer
list file number
1 Answer(s)      5 years and 7 months ago
Posted in : Java Beginners



Advertisement
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... 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
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
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
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
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
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
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 
List
List  i do have one list object, i want to compare this list from database table and if match found i want to update the list
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
List
List  getting values from a form and make a list of them and store them into database
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
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
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
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
JSP List Size
return the number of elements are added to the list.  Understand with Example... JSP List Size          JSP List Size is used to get the size
linked list
linked list   how to add student and mark and number from file in linked list and print them also how to make search function plz can help me sooon
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
Java get File List
Java get File List      ... the directory 'C:\\" to the constructor of class File.  file.listFiles...[]){  File file = new File("C:\\");    
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<
Linked List
removeFromFront(); public Object removeFromBack (); public boolen isEmpty(); } The number in the following logical linked list represents Computer Number. 76(head) 98 54...? to ?66?. The segment should also display the new contents of the linked list
Retrieve the dynamic capacity of a list
of a list i.e. retrieving the number of objects contained in it. Here is an example... using add(object) method. Now retrieve the total number of objects contained
 

 

 

DMCA.com