feat: complete all files
This commit is contained in:
@@ -5,39 +5,21 @@ import java.io.IOException;
|
||||
|
||||
public class CreateFileExample01 {
|
||||
static void main() {
|
||||
File file = new File("quotes.txt");
|
||||
try {
|
||||
File file = new File("texts/examples.txt");
|
||||
try
|
||||
{
|
||||
if(file.createNewFile())
|
||||
{
|
||||
System.out.println("created new file");
|
||||
System.out.println("File created");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("file already exists");
|
||||
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) {
|
||||
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.
|
||||
}
|
||||
|
||||
@@ -6,20 +6,11 @@ import java.nio.file.Path;
|
||||
|
||||
public class CreateFileExample02 {
|
||||
public static void main(String[] args) {
|
||||
Path path = Path.of("quotes.txt");
|
||||
Path path = Path.of("exmaples.txt");
|
||||
try {
|
||||
Files.createFile(path);
|
||||
} catch (IOException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
Path newPath = Path.of("newfolder/quotes.txt");
|
||||
try {
|
||||
// Files.createDirectories(newPath.getParent());
|
||||
Files.createFile(newPath);
|
||||
} catch (IOException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user