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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sumer
listing files
2 Answer(s)      5 years and 7 months ago
Posted in : Java Beginners



Advertisement
View Answers

April 16, 2009 at 3:45 PM


Hi friend,

Code to help in solving the problem :

import java.io.*;

public class DirListing{
private static void dirlist(String fname){
File dir = new File(fname);
String[] chld = dir.list();
if(chld == null){
System.out.println("Specified directory does not exist or is not a directory.");
System.exit(0);
}else{
for(int i = 0; i < chld.length; i++){
String fileName = chld[i];
System.out.println(fileName);
}
}
}
public static void main(String[] args){
switch(args.length){
case 0: System.out.println("Directory has not mentioned.");
System.exit(0);
case 1: dirlist(args[0]);
System.exit(0);
default : System.out.println("Multiple files are not allow.");
System.exit(0);
}
}
}

Thanks


April 16, 2009 at 3:45 PM


Hi friend,

Code to help in solving the problem :

import java.io.*;

public class DirListing{
private static void dirlist(String fname){
File dir = new File(fname);
String[] chld = dir.list();
if(chld == null){
System.out.println("Specified directory does not exist or is not a directory.");
System.exit(0);
}else{
for(int i = 0; i < chld.length; i++){
String fileName = chld[i];
System.out.println(fileName);
}
}
}
public static void main(String[] args){
switch(args.length){
case 0: System.out.println("Directory has not mentioned.");
System.exit(0);
case 1: dirlist(args[0]);
System.exit(0);
default : System.out.println("Multiple files are not allow.");
System.exit(0);
}
}
}

Thanks


Related Tutorials/Questions & Answers:
listing files - Java Beginners
listing files  how to list the files and number of files only...]); System.exit(0); default : System.out.println("Multiple files...]); System.exit(0); default : System.out.println("Multiple files are not allow
PHP listing files in folder
All files, folder   of the given folder can be listed. Function readdir() takes input as the folder handle. Then readdir() returns the name of all the files and folders. Example of PHP Listing Files in Folder
Advertisements
files
/core/files/storeobjectsinFile.html
files
files  write a java program to calculate the time taken to read a given number of files. file names should be given at command line.   Hello Friend, Try the following code: import java.io.*; import java.util.*; class
Listing all even numbers between two numbers
Listing all even numbers between two numbers  Hi, How to write code to list all the even numbers between two given numbers? Thanks   Hi, You function will take 2 numbers and the find the even numbers between
Listing Contents of a ZIP File
Listing Contents of a ZIP File       Section, provides the way for listing all the elements of a zip file through the java code. Following program helps you for the appropriate
Listing out leap years between certain period
Listing out leap years between certain period  ... the coding for finding and listing out the leap years between two years... will be a leap year. For listing out each year write "+n"
configuration files - Java Beginners
configuration files  i have to use configuration file in my program "listing of number of files and their modified time of directory",but problem is that directory name should be provided through configuratin file not input
header files
header files   do you have a all header files of java
Java Directory - Directory and File Listing Example in Java
Java Directory - Directory and File Listing Example in Java...; This example illustrates how to list files and folders present in the specified...);  and retrieves the list of all the files and folders present
Uploading files
Uploading files  Hi, Please provide html code for my question. I need to insert the browsed files temporarily to text area while attaching more than one files during mailing
validation files
validation files  If I place validation files in the folder where the action classes are present,will there any error arise
Given a code listing, determine whether it is a legal and appropriate way to programmatically access a caller's security context.
Given a code listing, determine whether it is a legal and appropriate way to programmatically access a caller's...;Next    Given a code listing, determine whether
configuration files are used in Struts
configuration files are used in Struts  What configuration files are used in Struts
files uploding and downloading codes
files uploding and downloading codes  any one know JSP codes for upload files,download files and delete files from a created virtual memory
Java JAR Files
output_files Get JAR file listing jar -tf  jar_file_name... Java JAR Files       A JAR file is a collection of  class files and auxiliary resources associated
invoking exe files on sound
invoking exe files on sound  how to invoke .exe files on input as sound in java
download pdf files
download pdf files  pls help me,I don't know how to convert .doc,.docx files into pdf files and download that pdf files using servlet or jsp
replacing regex in large files
replacing regex in large files  replacing regex in large files
php merge files
php merge files  Split and merge files in PHP Classes
Retrieving list of uploaded files.
Retrieving list of uploaded files.  I need to retrieve list of files... files on a website. its uploaded. now the file resides in a directory in the server. now the list of uploaded files should be showing in page where other users can
get files list - Ajax
get files list  Please,friend how to get files list with directories from ftp server or local files on web browser. Thanks, Tin Linn Soe   Hi friend, Index of Files Index
library files - Development process
library files   Hi members, i am trying to develop a media player in java using netbeans but what library files should i import for this development
files - Java Beginners
files  Why do we require files to store data?  Hi friend, files to store data, easy to find and access them. Thanks
 

 

 

DMCA.com