private static void listPhoneBooks(String curDirectory) throws IOException, ParseException {
   File myDir = new File(curDirectory);
   String[] filenames = myDir.list();
   ArrayList<String> phoneBooks = new ArrayList<String>();
   for (int i = 0; i < filenames.length; i++) {
     int temp = filenames[i].lastIndexOf(".");
     if (temp > 0) {
       String ext = filenames[i].substring(temp + 1);
       if (ext.compareTo("txt") == 0) {
         phoneBooks.add(filenames[i].substring(0, temp));
       }
     }
   }
   displayPhoneBooks(phoneBooks);
 }
示例#2
0
文件: Macro.java 项目: bramk/bnd
 /**
  * Get the contents of a file.
  *
  * @param in
  * @return
  * @throws IOException
  */
 public String _cat(String args[]) throws IOException {
   verifyCommand(args, "${cat;<in>}, get the content of a file", null, 2, 2);
   File f = domain.getFile(args[1]);
   if (f.isFile()) {
     return IO.collect(f);
   } else if (f.isDirectory()) {
     return Arrays.toString(f.list());
   } else {
     try {
       URL url = new URL(args[1]);
       return IO.collect(url, "UTF-8");
     } catch (MalformedURLException mfue) {
       // Ignore here
     }
     return null;
   }
 }
示例#3
0
  public void setDirectory(File d, FilenameFilter f) {
    if (d == null || !d.isDirectory()) {
      directory = null;
      filenames = new String[0];
    } else {
      if (f != null) {
        filenameFilter = f;
      }

      directory = d;
      filenames = directory.list(filenameFilter);
      if (filenames != null) { // cannot access directory ?
        Arrays.sort(filenames);
        dirType = new boolean[filenames.length];
        for (int i = 0; i < filenames.length; ++i) {
          // I hate generating objects like this..
          dirType[i] = (new File(d, filenames[i])).isDirectory();
        }
      } else {
        filenames = new String[0];
      }
    }
    fireTableStructureChanged();
  }