扫描文件名称

public static void main(String[] args) {
  // TODO Auto-generated method stub

  int j = 0;
  while(j<5) {
   File f = new File("c:/Mailboxes/in/");
   File[] fArray = f.listFiles();
   for(int i=0; i<fArray.length; i++) {
    if(fArray[i].getName().matches("[\\w]*.EML$")) {
     System.out.println(fArray[i].getName());
     try {
      FileInputStream is = new FileInputStream(fArray[i]);
      byte[] b = new byte[(int)fArray[i].length()];
      is.read(b);
      FileOutputStream os = new FileOutputStream("c:/mail/" + fArray[i].getName());
      os.write(b);
      os.close();
      is.close();
      fArray[i].delete();
     } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     }
    }
   }
   try {
    Thread.sleep(1000);
   } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   j++;
  }
 }

你可能感兴趣的:(文件)