|
|
Исходный текст программы DirTree.java
|
Оглавление |
Назад
// ==========================================
// DirTree.java
// (C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web: http://www.glasnet.ru/~frolov
// ==========================================
import java.io.*;
import java.util.*;
public class DirTree
{
public static void main(String args[])
{
String s;
while(true)
{
System.out.println(
"Enter full path ('quit' to exit): ");
s = new String(getKbdString());
if(s.equals("quit"))
break;
File f = new File(s);
if(!f.exists())
{
System.out.println("\nNot found: " + s);
continue;
}
if(!f.isDirectory())
{
System.out.println(
"\nNot directory: " + s);
continue;
}
list(s);
}
}
// ============================================
// list
// ============================================
static void list(String szDir)
{
int i;
File f = new File(szDir);
String[] sDirList = f.list();
for(i = 0; i < sDirList.length; i++)
{
File f1 = new File(szDir +
File.separator + sDirList[i]);
if(f1.isFile())
System.out.println(szDir +
File.separator + sDirList[i]);
else
{
list(szDir +
File.separator + sDirList[i]);
}
}
}
// ============================================
// getKbdString
// ============================================
static public String getKbdString()
{
byte bKbd[] = new byte[256];
int iCnt = 0;
String szStr = "";
try
{
iCnt = System.in.read(bKbd);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
szStr = new String(bKbd, 0, iCnt);
szStr = szStr.trim();
return szStr;
}
}
|
|
|