File 类java
Java.io.File 类表明系统文件名安全
File类的常见构造方法:spa
Public File(String pathname)以pathname为路径建立File对象,若是pathname是相对路径,则默认当前路径在系统属性指针
public File(String parent, String child)以parent为父路径,child为子路径建立File对象code
File的静态属性String separator存储了当前系统的路径分隔符对象
File 经常使用方法blog
经过File对象能够访问文件的属性接口
public boolean canRead();element
public boolean canWrite();rem
public boolean exists();
public boolean isDirctory();
public boolean isFile();
public boolean isHidden();
public long lastMOdified();//上次修改的时间
public long length();
public String getName();
public String getPath();
经过File对象建立空文件或目录(在该对象所指的文件或目录不存在的状况下)
public boolean creatNewFile() throws IOException
public boolean delete()
public booean mkdir();
public boolean mkdirs();
枚举类型 enum
枚举类型:1 只可以取特定值中的一个
2.使用enum关键字
3.是java.lang.Enum类型
Collection
java.util
Collection接口定义了存取一组对象的方法,其子接口Set和List分别定义了存储方式
Map接口定义了存储 key-value
int size();
boolean isEmpty();
void clear();
boolean contains(Object element);
boolean add(Object element);
boolean remove(Object element);
Iterator iterator();
boolean containAll(Collection c);
boolean addAll(Collection c);
boolean removeAll(Collection c);
boolean retainAll(Collection c);
Object [] toArray();
在remove Object的过程当中,要重写equals
容器类对象在调用remove、contains等方法时须要比较对象是否相等,这会涉及到对象类型的equals方法和hashcode方法;对于自定义的类型,须要重写equals 和 hashCode方法以实现自定义的对象相等规则。
public boolean equals(Object obj){
if ( obj instanceof Name ){
Name name = (Name) obj;
return (firstName.equals(name.firstName))&&(lastName.equals(name.lastName));
}
return super.equals(obj);
p.s 相等的对象应该具备相等的hashcodes
重写equals 方法 必须重写hashCode方法
Iterator
全部实现了Collection 接口的容器类都有一个iterator方法用以返回一个实现了Iterator接口的对象
boolean hasNext() // return true if the iteration has more elements
Object next() returns the next element in the iteration
void remove() removes from the underlying collection the last element returned by the iterator
父类(Iterator) 指向子类对象 (Collection)
Iterator 至关于一个指针 可是不一样的collection 有不一样的实现
Iterator对象的remove方法是在迭代过程当中删除元素惟一的安全方法