-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
96 lines (81 loc) · 4.1 KB
/
Main.java
File metadata and controls
96 lines (81 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.dj;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
public class Main {
public static void main(String[] args) {
try {
// Path filesToCreate = FileSystems.getDefault().getPath("Examples", "files2.txt");
// Files.createFile(filesToCreate);
// Path dirToCreate = FileSystems.getDefault().getPath("Examples", "Dir4");
// Files.createDirectory(dirToCreate);
// Path dirToCreate = FileSystems.getDefault().getPath("Examples", "Dir2/Dir3/Dir4/Dir5/Dir6");
// Path dirToCreate = FileSystems.getDefault().getPath("Examples/Dir2/Dir3/Dir4/Dir5/Dir6/Dir7");
// Files.createDirectories(dirToCreate);
Path filePath = FileSystems.getDefault().getPath("Examples", "Dir1\\file1.txt");
long size = Files.size(filePath);
System.out.println("Size = " + size);
System.out.println("Last modified = " + Files.getLastModifiedTime(filePath));
BasicFileAttributes attrs = Files.readAttributes(filePath, BasicFileAttributes.class);
System.out.println("Size = " + attrs.size());
System.out.println("Last modified = " + attrs.lastModifiedTime());
System.out.println("Created = " + attrs.creationTime());
System.out.println("Is directory = " + attrs.isDirectory() );
System.out.println("Is regular file = " + attrs.isRegularFile());
// Path filesToDelete = FileSystems.getDefault().getPath("Examples", "Dir1", "file1copy.txt");
// Files.delete(filesToDelete);
// Path fileToMove = FileSystems.getDefault().getPath("Examples", "file1.txt");
// Path destination = FileSystems.getDefault().getPath("Examples", "file1.txt") ;
// Files.move(fileToMove, destination);
// Path sourceFile = FileSystems.getDefault().getPath("Examples", "file1.txt");
// Path copyFile = FileSystems.getDefault().getPath("Examples", "file1copy.txt");
// Files.copy(sourceFile, copyFile, StandardCopyOption.REPLACE_EXISTING);
//
// sourceFile = FileSystems.getDefault().getPath("Examples", "Dir1");
// copyFile = FileSystems.getDefault().getPath("Examples", "Dir4");
// Files.copy(sourceFile, copyFile, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
// Path path = FileSystems.getDefault().getPath("WorkingDirectoryFile.txt");
// printFile(path);
//// Path filePath = FileSystems.getDefault().getPath("files", "SubdirectoryFile.txt");
// Path filePath = Paths.get(".","files", "SubdirectoryFile.txt");
// printFile(filePath);
// filePath = Paths.get("C:\\Users\\shree\\IdeaProjects\\OutThere.txt");
// printFile(filePath);
//
// filePath = Paths.get(".");
// System.out.println(filePath.toAbsolutePath());
//
// Path path2 = FileSystems.getDefault().getPath(".", "files", "..", "files", "SubdirectoryFile.txt");
// System.out.println(path2.normalize().toAbsolutePath());
// printFile(path2.normalize());
//
// Path path3 = FileSystems.getDefault().getPath("thisfiledoesn'texist.txt");
// System.out.println(path3.toAbsolutePath());
//
// Path path4 = Paths.get("Z:\\", "abcdef", "whatever.txt");
// System.out.println(path4.toAbsolutePath());
//
// filePath = FileSystems.getDefault().getPath("files");
// System.out.println("Exists = " + Files.exists(filePath));
//
// System.out.println("Exists = " + Files.exists(path4));
// }
//
// private static void printFile(Path path) {
// try(BufferedReader fileReader = Files.newBufferedReader(path)) {
// String line;
// while((line = fileReader.readLine()) != null) {
// System.out.println(line);
// }
// } catch(IOException e) {
// System.out.println(e.getMessage());
// e.printStackTrace();
// }
// }
}