3.4 Files

简介: 3.4 Files

检查文件是否存在 Path path = Paths.get("helloword/data.txt"); System.out.println(Files.exists(path));

创建一级目录 Path path = Paths.get("helloword/d1"); Files.createDirectory(path);

  • 如果目录已存在,会抛异常 FileAlreadyExistsException
  • 不能一次创建多级目录,否则会抛异常 NoSuchFileException

创建多级目录用

Path path = Paths.get("helloword/d1/d2"); Files.createDirectories(path);

拷贝文件

Path source = Paths.get("helloword/data.txt"); Path target = Paths.get("helloword/target.txt");

Files.copy(source, target);

  • 如果文件已存在,会抛异常 FileAlreadyExistsException

如果希望用 source 覆盖掉 target,需要用 StandardCopyOption 来控制

Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);



目录
相关文章
|
C#
C# File、FileInfo、Directory、DirectoryInfo
本文主要介绍文件类、文件信息类、目录类、目录信息类的常用属性和方法
63 0
|
8月前
|
Shell
adb: error: cannot create file/directory ‘d:/1.png‘: No such file or directory
adb: error: cannot create file/directory ‘d:/1.png‘: No such file or directory
133 0
Get Files In Folder [ DTFolderFiles ] Plug-in description
Get Files In Folder [ DTFolderFiles ] Plug-in description
56 0
files 2
files 2
77 0
Get Files In Folder [ DTFolderFiles ] 插件说明
Get Files In Folder [ DTFolderFiles ] 插件说明
82 0
Get Files In Folder [ DTFolderFiles ] 插件说明
objdump: ‘1443.14.0)‘: No such file or directory
objdump: ‘1443.14.0)‘: No such file or directory
114 0
curses.h: No such file or directory
curses.h: No such file or directory
135 0
No such file or directory
No such file or directory
326 0
No such file or directory
FILE
FILE
124 0
|
文字识别
解决pytesseract.pytesseract.TesseractError: (1, ‘Error opening data file C:\\Program Files\\Tesseract-
pytesseract.pytesseract.TesseractError: (1, ‘Error opening data file C:\Program Files\Tesseract-OCR\tessdata/chi_sim.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your “tessdata” directory. Failed loading language ‘chi_sim’ Tesseract couldn’t load any languages! Cou
1501 0
解决pytesseract.pytesseract.TesseractError: (1, ‘Error opening data file C:\\Program Files\\Tesseract-