Question

In: Computer Science

Write a java program to let the user enter the path to any directory on their...

Write a java program to let the user enter the path to any directory on their computers. Then list all the files in that directory.

Solutions

Expert Solution

I have written the program using JAVA PROGRAMMING LANGUAGE.

INPUT:

OUTPUT :

CODE :

//imported the java.io.File

import java.io.File;

//Main Class

public class Main

{

static void FilesPrint(File[] arr,int index)

{

// To exit the recursive calls

if(index == arr.length)

return;

//to print the file/folder name on the console

System.out.println(arr[index].getName());

// Calling FilesPrint recursively by increasing the index value by one

FilesPrint(arr,++index);

}

// Driver Method

public static void main(String[] args)

{

// Provide full path for directory

//C:\\Users\\ponnada kumar\\Desktop\\Practice

String maindirpath = "input";

    

// File object

File maindir = new File(maindirpath);

if(maindir.exists() && maindir.isDirectory())

{

// To get the list Files in the given Directory

File arr[] = maindir.listFiles();

//Just a print statement

System.out.println("\nFiles/Folders from the given Directory : ");

// Calling FilesPrint

FilesPrint(arr,0);

}

}

}

Thanks..


Related Solutions

​​​​​​​For java program. Write a while loop that will let the user enter a series of...
​​​​​​​For java program. Write a while loop that will let the user enter a series of integer values and compute the total values and number of values entered. An odd number will stop the loop. Display the number of iterations and the total of the values after the loop terminates. for Loop Write a for loop to display all numbers from 13 - 93 inclusive, ending in 3. Write a for loop to display a string entered by the user...
Problem Description: Write a program that prompts the user to enter a directory and displays the...
Problem Description: Write a program that prompts the user to enter a directory and displays the number of the files in the directory. Analysis: (Describe the problem including input and output in your own words.) Design: (Describe the major steps for solving the problem. How do you use recursion to solve this problem.) Coding: (Copy and Paste Source Code here. Format your code using Courier 10pts) Name the public class Exercise18_29 Testing: (Describe how you test this program)
Write a java program that lets the user to enter any two integers and weave them...
Write a java program that lets the user to enter any two integers and weave them digit by digit and print the result of weaving their digits together to form a single number. Two numbers x and y are weaved together as follows. The last pair of digits in the result should be the last digit of x followed by the last digit of y. The second-to-the-last pair of digits in the result should be the second-to- the-last digit of...
Create JAVA PROGRAM, and write comment for codes also. 1) Let the user enter in candidate...
Create JAVA PROGRAM, and write comment for codes also. 1) Let the user enter in candidate names for a ballot. Then imagine the program is moved to a voting booth. Each voter enters their unique name and who they vote for, and when there are no more voters display who won. (Imagine something outside your program is telling it there are no more voters.)
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Write a java program. The program requirements are: the program will let the user input a...
Write a java program. The program requirements are: the program will let the user input a starting number, such as 2.  It will generate ten multiplication problems ranging from 2x1 to 2x10.  For each problem, the user will be prompted to enter the correct answer. The program should check the answer and should not let the user advance to the next question until the correct answer is given to the question being asked currently. After testing a total of 10 multiplication problems,...
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
Write a java program that does the following: a) The user will enter data such as...
Write a java program that does the following: a) The user will enter data such as client name and client balance. The user can stop inputting data by entering "stop". The program should store the user inputs as a data member of an array. The type of this array is a class named ClientData. Below the output should be displayed by the program. The parts in bold are inputs from the user and not hard coded in the program Client...
In java, write a program that asks the user to enter a character. Then pass the...
In java, write a program that asks the user to enter a character. Then pass the character to the following methods. isVowel() – returns true if the character is a vowel isConsonant() – returns true if the character is a consonant changeCase() – if the character is lower case then change it to upper case and if the character is in upper case then change it to lower case. (return type: char) Example output is given below: Enter a character...
JAVA Write a program that will compare two names. The program prompts the user to enter...
JAVA Write a program that will compare two names. The program prompts the user to enter two names for a comparison. If the names are same, the program states that. If the names are different, the program converts both names to UPPERCASE, and compares then again. If they are equal, the programs displays a message stating that names are equal if CASE is ignored. Otherwise, the program prints names with a message that names are not equal.  Check also if there...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT