Plz give me code for this question

Plz give me code for this question

Program to find depth of the file in a directory and list all files those are having more number of parent directories.

View Answers

August 5, 2011 at 3:04 PM

import java.io.*;
import java.util.*;
class  ListAllFiles{
     static int  size = 20;         
    public static void main(String[] args) {
        System.out.print("Enter the name of a directory for listing:");
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String root = in.next();
            File file = new File(root);
            if (file != null && file.isDirectory()) {
                displayList(file, 0);
            }      
            }
    }
    public static void displayList(File f, int depth) {
        if(f.isFile()){
        System.out.println(f.getName()); 
        }
        if (f.isDirectory()  && depth <= size) {
            File[] dir = f.listFiles(); 
            for (File ff : dir) {
            displayList(ff, depth+1); 
            }
        }
    }

For more information, please visit the following links:

http://www.roseindia.net/java/example/java/io/TraversingFileAndDirectories.shtml

http://www.roseindia.net/tutorial/java/core/files/filelistfiles.html









Related Tutorials/Questions & Answers:
Plz give me code for this question
Plz give me code for this question  Program to find depth of the file in a directory and list all files those are having more number of parent directories
plz give me answer plz
plz give me answer plz  writw a programme to find rank from an array using doubledimmensionalarray
Advertisements
plz give me answer
plz give me answer   description about string class methods   Java string methods
plz give me answer
plz give me answer   description about string class methods   Java string methods
plz give me answer
plz give me answer   description about string class methods   Java string methods
plz give me answer
plz give me answer  Discuss & Give brief description about string class methods   Java string methods
plz help me for this question
plz help me for this question  Apply simplex procedure to solve the L.P.P. maximize z = 3x1 + 4x2 subject to 5x1 + 4x2 â?¤ 200; 3x1 + 5x2 â?¤ 150; 5x1 + 4x2 â?¥ 100; 8x1 + 4x2 â?­â?¥ 80, x1 â?¥ 0, x2 â?¥ 0
StringIndexOutOfBound error !!! plz give me the reason for this error ,plz.........
StringIndexOutOfBound error !!! plz give me the reason for this error ,plz.........  import java.util.Scanner; class Even { static int getEven(int firstno,int secondno) { int counteven=0; for(int i=firstno;i<=secondno;i
please give me an idea to develop a program for this question?
please give me an idea to develop a program for this question?  How to enter a text or number from keyboard without using InputStreamReader method in java
Give me the source code for this problem
Give me the source code for this problem  Ram likes skiing a lot. That's not very surprising, since skiing is really great. The problem with skiing is one have to slide downwards to gain speed. Also when reached the bottom most
ModuleNotFoundError: No module named 'give_me_code'
ModuleNotFoundError: No module named 'give_me_code'  Hi, My Python... 'give_me_code' How to remove the ModuleNotFoundError: No module named 'give_me_code' error? Thanks   Hi, In your python
verify the code and give me the code with out errors
verify the code and give me the code with out errors   import... clear the errors and give me correct tutorial for my knowledge improving.pls anyone help me. E:\>java add java.lang.NullPointerException at add
interview question plz help me and thers
interview question plz help me and thers  A college is good if it satisfies the following conditions: 1.Its number of students is greater than 1000. 2.If the name ends wih a character 'e', then it should not start with character
Plz help me in writing the code - Java Beginners
Plz help me in writing the code   Write a two user Chess Game. (users must be on different systems
Plz help me in writing the code - Java Beginners
Plz help me in writing the code   Write a two user Chess Game. (users must be on different systems
Plz help me with this Question - Java Beginners
Plz help me with this Question  this is java code ------------------------- Consider the following code: int [ ] a = [1, 2, 3]; Object o ="123... the effect of executing this code by means of a diagram similar to that in Figure
please give me a java program for the following question
please give me a java program for the following question  Write...; In the previous code, we forget to add an icon to button. So we are sending the updated code. import java.awt.*; import javax.swing.*; import
PLZ HELP ME. i need php code.
PLZ HELP ME. i need php code.   I want php code for bellow OUTPUT. output is just example but it must be letters only. abc bcd efg jku rgt azs hje qqc wws adt
please help me to give code - Java Beginners
please help me to give code  Write a function with a signature cheerlead(word) that prints a typical cheer as follows. The word robot: Gimme an R Gimme an O Gimme a B Gimme an O Gimme a T What did you give me? ROBOT
please help me to give code - Java Beginners
please help me to give code  Write a function, sliding(word, num)that behaves as follows. It should print out each slice of the original word having length num, aligned vertically as shown below. A call to sliding(examples, 4
please help me to give code - Java Beginners
please help me to give code  Write a program that prints an n-level stair case made of text. The user should choose the text character and the number of stairs in the stair case * ** *** ****   Hi friend
please help me to give code - Java Beginners
please help me to give code  Write a program that uses loops to generate an n x n times table. The program should get n from the user. As a model here is a 4 x4 version: | 1 2 3 4
please help me to give code - Java Beginners
please help me to give code  Write a program that reads a file named famous.txt and prints out the line with the longest length. In the case of a tie, you may print out only one of them. For example in the file: Alan Turing
Clear Question plz et me know immediately - Java Beginners
Clear Question plz et me know immediately   Hi Deepak your application is good,pls modify this application and let me know My problem is that, Steps: 1:- A form have three 3 button delete,insert,edit. 2
how to send email please give me details with code in jsp,servlet
how to send email please give me details with code in jsp,servlet  how to send email please give me details with code in jsp,servlet
give me source code of webpage creation using html
give me source code of webpage creation using html  how to create a webpage using html
hi... pls give me the example of java coding fo following question
hi... pls give me the example of java coding fo following question  example java coding that reads in the radius and length of cylinder and computes volume. formula: Area = radius * radius * PI Volume = area * length
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that prompts the user to enter the number of students and each studentâ??s name and score, and finally displays the name of the students
I didn't gat an output for this code, plz send me a correct code
I didn't gat an output for this code, plz send me a correct code  Hi, Here is my code: import java.awt.event.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.*; import java.sql.*; public
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that reads in investment amount, annual interest rate, and number of years, and displays the future investment value using the following formula
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Suppose that the tuition for a university is RM10,000 this year and increases 5% every year. Write a program that computes the tuition in ten years and the total cost
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a function called ChangeToNext that take in an uppercase character parameter ch. The function returns the next uppercase character if ch is between 'A' and 'Y
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that displays the following table (note that 1 mile is 1.609 kilometers). Miles Kilometers
sir i,have a assignment for these question plz help me sir - JavaMail
sir i,have a assignment for these question plz help me sir   1.Design a Java interface for ADT Stack. Develop two different classes that implement this interface, one using array and the other using linked-list. Provide
hi... pls give me the example of java coding for following question
hi... pls give me the example of java coding for following question   Write a program that computes loan payments. The loan can be a car loan, a student loan, or a home mortgage loan. The program lets the user enter the interest
hi... pls give me the example of java coding fo following question
hi... pls give me the example of java coding fo following question  Write a java program that reads the following information and prints a payroll statement: Employeeâ??s name (e.g: Sam) Number of hours worked in a week (e.g: 10
plz give me program to this: Given a string and a number ‘n’, find the ‘n’th distinct repeating character.
plz give me program to this: Given a string and a number ?n?, find the ?n?th distinct repeating character.    Given a string and a number ?n?, find the ?n?th distinct repeating character. For example, Input: Abracadabra, 1
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Body Mass Index(BMI) is a measure of health on weight. It can be calculated by taking your weight in kilograms and dividing by the square of your height in meters
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a class that contains the following two methods: /* converts from inches to centimeters */ Public static double inchToCentimeter(double in) /* converts from
plz tell me the code & execution process - Java Beginners
plz tell me the code & execution process  Write a program to download a website from a given URL. It must download all the pages from that website. It should take the depth of retrieval from the user input. All the files/pages
Pleae help me to give logic and code for this program - Java Beginners
Pleae help me to give logic and code for this program  Write a function that given the string ?original? create a new string ?dramatic? that has two consecutive copies of each letter from the original string. For example
plz tell me the code & execution process - Java Beginners
plz tell me the code & execution process  Write a program to download a website from a given URL. It must download all the pages from that website... must be stored in a folder.  Hi friend, Code to help in solving
Please give me the code for the below problem - Java Interview Questions
Please give me the code for the below problem  PROBLEM : SALES TAXES Basic sales tax is applicable at a rate of 10% on all goods, except books... Vidya  Hi Friend, Try the following code: import java.util.
very urgent : Iam unable to code this program plz help me - RMI
very urgent : Iam unable to code this program plz help me  Write a Multi-user chat server and client.  Hi friend, Chat server is a standlone application that is made up the combination of two-application, server
Plz give java coding for this
Plz give java coding for this   ****** * * * *********** * * * ******   Hello Friend; below is the code... iMin = 1, iMax = 8, iMid; // give max. value in even no. int jMin = 1, jMax
plz plz plz inform me as soon as possible
plz plz plz inform me as soon as possible  ``by using c programs how to type
please any one can help me to write a code for this question?
please any one can help me to write a code for this question?  1) Copy one file content to other? 2) Count the number of words in a file
sir i,have a another assignment for these question plz help me sir - JavaMail
sir i,have a another assignment for these question plz help me sir  1. Design classes for Currency, Rupee, and Dollar. Write a program... to both. plz help me sir
Help me quickly plz??
Help me quickly plz??  Can you help me to write code quickly this code is a java code take input as double and should use command line arguments and enhanced for statement then find the combine of the numbers plz help quickly
please any one can help me to write a code for this question?
please any one can help me to write a code for this question?  Q 1) In a class first day 25 students are joined. After two days that total students will increased to 60. We can develop a program by using ArrayList concept

Ads