 |
|
|
ls.java
|
/*
* Author: Havard Rast Blok
* E-mail: 
* Web : www.rememberjava.com
*/
import java.io.File;
/**
* Lists the files in the current directory. One file per line.
* Similuar to "dir /b" in DOS-prompt of Windows or
* "ls -1" in Linux
*/
public class ls
{
public ls()
{
String homeDir = "";
File file;
String fileList[];
//Get the current directory
try
{
homeDir = System.getProperty( "user.dir" );
}
catch(Exception e)
{
System.out.println("ls.ls - Unable to retrieve current directory: "+e);
System.exit(1);
}
//Get file names of the current directory
file = new File( homeDir );
fileList = file.list();
if( fileList == null )
{
System.out.println("ls.ls - Error accessing current directory.");
System.exit(1);
}
//List the files in the current directory. One file per line.
for(int i = 0; i < fileList.length; i++)
{
System.out.println(fileList[i]);
}
}
public static void main( String [] args)
{
new ls();
}
}
|
|
|
 |