zoukankan      html  css  js  c++  java
  • 学习java第24天

    1.文件类

    *创建File类对象

    File f;

    f = new File ("a.java");

    f = new File ("C:\nie\","a.java");

    *File类提供了实现目录管理功能的方法

    File path = new File("C:\nie\");

    File f = new File(path,"a.java");

    2.列出所有文件

    import java.io.*;
    class  ListAllFiles
    {
     public static void main(String[] args){
      ListFiles( new File( "c:\workspace"));
     }
     public static void ListFiles( File dir ){
      if( !dir.exists() || ! dir.isDirectory() ) return;
      
      String [] files = dir.list();
      for( int i=0; i<files.length; i++){
       File file = new File( dir, files[i] );
       if( file.isFile() ){
        System.out.println(
         dir + "\" + file.getName() + " " + file.length() );
       }else{
        System.out.println(
         dir + "\" + file.getName() + " <dir>" );
        
        ListFiles( file );  //对于子目录,进行递归调用
       }
      }
     }
    }
    3.Pattern类
    import java.util.regex.*;
    public class RegexSplitter {
     public static void main(String[] args) throws Exception {
      Pattern p = Pattern.compile( "[, \s]+");
      String[] result =
       p.split( "one,two, three   four ,  five ");
      for (int i=0; i<result.length; i++)
       System.out.println(result[i]);
     }
    }
    4.匹配
    import java.util.regex.*;
    public class RegexEmailValidate {
     public static void main(String[] args)
       throws Exception {
      String pattern = "^[^@]+@[\w]+(\.[\w]+)*$";
      String email = "dstang2000@263.net";
      boolean ok = Pattern.matches( pattern, email );
      System.out.println( ok );
     }
    }
    5.Matcher类
    mport java.util.regex.*;
    public class RegexReplacement {
     public static void main(String[] args)
       throws Exception {
      Pattern pattern = Pattern.compile("cat");
      Matcher matcher = pattern.matcher(
       "one cat, two cats in the yard");
      StringBuffer sb = new StringBuffer();
      while(matcher.find()) {
       matcher.appendReplacement(sb, "big $0");
      }
      matcher.appendTail(sb);
      System.out.println(sb.toString());
     }
    }
     
    明天学习内容:
    组件
     
  • 相关阅读:
    Handsontable添加超链接
    Handsontable 筛选事件
    handsontable自定义渲染
    M1 Mac安装 Homebrew
    Pypi官网怎么找历史依赖包
    在 CentOS7 中我们在安装 MySQL
    Ansible使用yum安装
    Ansible集群自动化运维操作
    java对list中map集合中某个字段排序
    使用hive的orcfiledump命令查看orc文件
  • 原文地址:https://www.cnblogs.com/SirNie/p/13398824.html
Copyright © 2011-2022 走看看