Previously speaking,File can be seen as one ducument, also can be seen as list of documents like directory.

Here,File also can be seen as one directory which does't exist, also can be seen as  a whole path of directory which does't exist.

 

Example1:

File f = new File("C:/Users/caich5/Desktop/test");

if(!f.exist()){

f.mkdirs();

}

 If succeed,Directory 'test' will show in the path of 'C:/Users/caich5/Desktop';

 

File f = new File("C:/Users/caich5/Desktop/test/test/test");

if(!f.exist()){

f.mkdirs();

}

If succeed,Directory 'test/test/test' will show in the path of 'C:/Users/caich5/Desktop';

 

Tips:difference between file.mkdirs() and file.mkdir();

file.mkdirs(): it means that you can create multi-layer path;

file.mkdir(): it means that you can only create the single-layer path;

 

Example2:

File f = new File("C:/Users/caich5/Desktop/test.txt");

if(!f.exist()){

   f.createNewFile();

}

 

相关文章:

  • 2021-09-13
  • 2022-12-23
  • 2021-11-23
  • 2021-07-24
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
猜你喜欢
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2021-12-24
  • 2022-01-02
  • 2022-12-23
相关资源
相似解决方案