Java
JavaBase
Implementation in java to determine whether a file exists and create it if it does not existImplementation in java to determine whether a file exists and create it if it does not exist

一、判断文件是否存在,不存在则创建
File file = new File("d:\\test.txt");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("文件已创建");
} else {
System.out.println("文件已存在");
}免费视频教程推荐:java免费视频教程
二、判断文件夹是否存在,不存在则创建
File folder = new File("d:\\test1\\test2");
if (!folder.exists() && !folder.isDirectory()) {
folder.mkdirs();
System.out.println("创建文件夹");
} else {
System.out.println("文件夹已存在");
}更多相关文章教程推荐:java语言入门
The above is the detailed content of Implementation in java to determine whether a file exists and create it if it does not exist. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Mac version
God-level code editing software (SublimeText3)




