Files
WS-05-exceptions-and-file-h…/src/main/java/org/FileExamples/CreatingFiles/CreateFileExample01.java
T
2026-05-10 16:35:22 +03:30

44 lines
1.1 KiB
Java

package org.FileExamples.CreatingFiles;
import java.io.File;
import java.io.IOException;
public class CreateFileExample01 {
static void main() {
File file = new File("quotes.txt");
try {
if(file.createNewFile())
{
System.out.println("created new file");
}
else
{
System.out.println("file already exists");
}
} catch (IOException e) {
System.err.println(e.getMessage());
}
File newfile = new File("newfolder/quotes.txt");
try {
newfile.getParentFile().mkdirs();
if(newfile.createNewFile())
{
System.out.println("created new file");
}
else
{
System.out.println("file already exists");
}
} catch (IOException e) {
System.err.println(e.getMessage());
}
}
//TODO: 1. Create File
//TODO: 2. Specify and address and directory that exists
//TODO: 3. Specify and address and directory that does not exists
//TODO: 4.
}