Plz give me code for this question

Ads
 

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

Ads









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  Discuss & Give brief 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   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. 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 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
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
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
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
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
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  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... 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
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
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
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
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

Ads