A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 丶江河 初级黑马   /  2019-8-1 15:58  /  730 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

File
*file类的概述和构造方法
     ^File的概述
           1 File是抽象路径名的表示,多表示的文件或者目录不一定存在
           2 创建方法
             File(String pathname)
                 File(String parent, String child)
                 File(File parent, String child)

   File(File parent, String child)
     根据 parent 抽象路径名和 child 路径名字符串创建一个新 File 实例。
   File(String pathname)
      通过将给定路径名字符串转换为抽象路径名来创建一个新 File 实例。
   File(String parent, String child)
       根据 parent 路径名字符串和 child 路径名字符串创建一个新 File 实例。
  *创建文件或目录
      1 File类的创建功能
            创建文件: createNewFile():用来创建一个文件,如果没有则创建,如果有则不创建
                创建目录: mkdir();只能创建一个
                          mkdirs();可以创建多层
          2 判断功能
               boolean exists(): 判断是否存在
                boolean  isDirectory(); 是否是是目录
                boolean  ifFile  :是否是文件
                String   getAbsolutePath(); 获取绝对路径
                String   getPath();获取相对路径
                Spring   getName();获取路径名
                list();  List ArrayList/LinkedList  //返回此抽象路径名表示的目录中的文件和目录的名称字符串数组
                File[] listFiles():返回此抽象路径名表示的目录中的文件和目录的File对象数组
               
          3 删除方法
            boolean delete():删除    注意:必须是空的 如果有文件是删除不成功的       
        public class Test{  
                   public static void main(String args[]){
                     File f  = new File("D:\\");
                           String [] str=f.list();
                 for(String s : str){                 
                                 }                  
                   }
               
                }
## 递归
## 字节流
     按流向划分
         输入流
                 输出流
    按单位
         字节流
         字符流 char c ='中';
         
         
        #字节流
          字节输入流: InputStream
           ^FileInputStream
           字节输出流:
           ^FileOutputStream
        #字节流读写文件
          读文件
            int read();
                int read(byte[] by);
          写文件
             write(int a)     byte[]b ={10,20,30,40}一次写一个
                 write(byte[], intoff,int len); 一次洗写多
* 单位换算
byte short int long
8     16   32   64

float  double
32      64
(8位)    (16位)



IO
按流向分
   输入流
     字节输入流 InputStream -->  FileInputStream
            读取数据的方法
                  read()/read(byte[])/read(byte[],0,lenth)
            缓冲字节输入流 BufferedlnputStream
        字符输入流 InputStreamReader(lnputStream is);       
            Reader --> FileReader
                缓冲字符输入流BufferedReader
                    String  readLine()
            
               
        输出流
        字节输出流 OutputStream  -->FileInputStream
        写数据write(int b)/write(byte[]by)/write(byte[],int offset,int lenthe)               
            缓冲字节输出流 BufferedWriter
                   newLine();
                  
        按处理单位分
            字节流
                字符流
**集合回顾
        Collection
          ^List 有序可重复
             ArrayList  底层是数组
             LinkedList
          ^ Set 无需元素不重复
                      HashSet
                          TreeSet
              ^ Map   键值对
                    HashMap
                        TreeMap       
回顾今天知识
**File类的构造方法:  
        File file =new File(String pathname);// 通过将给定路径名字符串转换为抽象路径名来创建一个新 File 实例。
        File file =new File(File parent,String child);//根据 parent 抽象路径名和 child 路径名字符串创建一个新 File 实例。
        File file = new File(String parent,String parent);//根据 parent 路径名字符串和 child 路径名字符串创建一个新 File 实例。
**File类的成员方法
    boolean file.createNewFile(); //当具有该名称的文件不存在时,创建一个由该抽象路径名命名的心空文件

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马