import java.util.*; import java.lang.*; import java.net.*; import java.io.*; public class ehat { public static void main(String args[]) { String pattern = " den "; String []ls =null; String content=""; try{ ls = list(args[0]," /B "); }catch(InterruptedException e) {; } for(int k=0;k den "; return pattern; } /** write data from "fileContent" into file with name "fileName" */ public static void writeFile(String fileName,String fileContent) { //System.out.println("I am writing the file:"+fileName+ // " content:"+fileContent); try{ FileOutputStream fw = new FileOutputStream(fileName); DataOutputStream dos = new DataOutputStream(fw); //write fileContent to file at once dos.writeBytes(fileContent); }catch(IOException e){ System.err.println("There is IOException during writing file:"+e); } } public static String [] list(String dir,String opts) throws InterruptedException { String separator = File.separator; boolean isExist=false,isRead=false; Vector lines = new Vector(); //check that this directory exists first File file = new File(dir); try{ if (file.exists()) isExist = true; isRead = true; }catch(SecurityException e){ System.out.println("Security Exception "+e); } if (!isRead){ System.out.println(dir+" is not readable"); lines.addElement("total xx"); lines.addElement("NotReadable"); } else if (!isExist){ System.out.println(dir+" Not Found"); lines.addElement("total xx"); lines.addElement("NotFound"); } if ((!isRead)||(!isExist)){ System.out.println("file "+dir+" not found or not readable"); String[] retval = new String[lines.size()]; lines.copyInto(retval); return retval; } try{ String line; String cmd=null,pwd=null; Process child; DataInputStream in; //start up the command if (separator.equals("/")) //UNIX cmd = "ls -al "+dir; else if (separator.equals("\\")) //WIN/NT cmd = "cmd.exe /C "+" DIR "+opts+" "+dir; //running dir on top of WIN/NT //cmd = "command.com /C "+" DIR "+dir; //running dir on top of DOS child = Runtime.getRuntime().exec(cmd); System.out.println("Before DIS "); in = new DataInputStream(child.getInputStream()); //read the command's output while((line = in.readLine()) != null){ lines.addElement(line); //System.out.println("line: "+line); } String[] retval = new String[lines.size()]; lines.copyInto(retval); return retval; } catch (Exception e){ throw new InterruptedException (e.toString()); } } }