关于File文件类的一些理解、

  1. 其中有一个API,是exists,判断当前文件对象表示的目录或者文件是否存在。
    File file = new File("");
    String absolutePath = file.getAbsolutePath();//得到的是当前这个项目的绝对位置,也就是项目的根位置。
    System.out.println(absolutePath);
    boolean exists = file.getParentFile().exists();//判断这个路径上的父目录是否存在,
    /*
    * C:\Users\peipe\IdeaProjects\courage
    * */
    if(!exists)
    file.getParentFile().mkdirs();//如果不存在,就按照路劲(目录结构)依次创建目录,依次创建Users、peipe、IdeaProjects、courage目录
    file.getParentFile().mkdir();//只创建courage目录

     RandomAccessFile randomAccessFile = new RandomAccessFile(file,"rw");
     ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
     byte[] bytes = outputStream.toByteArray();//直接得到字节数组
     PrintWriter printWriter = new PrintWriter(file);//得到打印流
     BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));//缓冲字节流
     BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));//缓冲字符流,并且有字节流转字符流方式

相关文章:

  • 2022-12-23
  • 2022-01-20
  • 2021-10-26
  • 2022-12-23
  • 2021-11-05
  • 2021-06-23
猜你喜欢
  • 2022-12-23
  • 2021-12-16
  • 2022-01-20
  • 2021-07-26
  • 2022-12-23
  • 2021-07-22
  • 2022-02-02
相关资源
相似解决方案