文件夹与文件的建立条件关系
public class FileTest {
public static void main(String[] args) {
String path = "D:\\1\\2";
File file = new File(path);
System.out.println(file.exists());
System.out.println(file.isDirectory());
file.mkdir();
System.out.println(file.exists());
System.out.println(file.isDirectory());
String path = "D:\\1\\2";
File file = new File(path);
System.out.println(file.exists());
System.out.println(file.isDirectory());
file.mkdirs();
System.out.println(file.exists());
System.out.println(file.isDirectory());
String path = "D:\\test.txt";
File file = new File(path);
System.out.println(file.exists());
System.out.println(file.isDirectory());
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(file.exists());
System.out.println(file.isDirectory());
String path = "D:\\1\\2";
File file = new File(path);
File tempFile = null;
try {
tempFile = file.createTempFile("hello", ".png");
System.out.println(tempFile.exists());
System.out.println(tempFile.isDirectory());
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(tempFile.exists());
System.out.println(tempFile.getAbsolutePath());
System.out.println(tempFile.getPath());
System.out.println(tempFile.getName());
System.out.println(tempFile.isDirectory());
String path = "D:\\1";
File file = new File(path);
File tempFile = null;
try {
tempFile = file.createTempFile("hello", ".png", file);
System.out.println(tempFile.exists());
System.out.println(tempFile.isDirectory());
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(tempFile.exists());
System.out.println(tempFile.getAbsolutePath());
System.out.println(tempFile.getPath());
System.out.println(tempFile.getName());
System.out.println(tempFile.exists());
System.out.println(tempFile.isDirectory());
}
}