-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadingFile.java
More file actions
105 lines (85 loc) · 2.43 KB
/
ReadingFile.java
File metadata and controls
105 lines (85 loc) · 2.43 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
97
98
99
100
101
102
103
104
105
/**
*
*/
package filesIO;
import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
/**
* @author rutpatel
*
*/
public class ReadingFile {
private static String filePath = "/Users/rutpatel/Documents/Rut/Collabera_JuMP/SpringTool_Workspace";
private static Map<Long, String> sortFile = new TreeMap<Long, String>();
public static void main(String[] args) throws IOException {
File file = new File(filePath);
if (file.exists()) {
sortDirectory(file);
}
for (Map.Entry<Long, String> entry : sortFile.entrySet()) {
Long key = entry.getKey();
String value = entry.getValue();
System.out.println(new Date(new Timestamp(key).getTime()) + " => " + value);
}
// File file = new File(filePath);
// if (file.exists()) {
// printDirectory(file);
// }
// File f = new File("test.txt");
// System.out.println("File Length - " + f.length());
// Scanner sc = new Scanner(f);
// while (sc.hasNext()) {
// System.out.println(sc.nextLine());
// }
// sc.close();
// FileInputStream fis = new FileInputStream(f);
// int data = fis.read();
// while (data != (-1)) {
// System.out.print((char)fis.read());
// data = fis.read();
// }
// fis.close();
// File f = new File("text.data");
// FileOutputStream fos = new FileOutputStream(f);
// String data = "Hello from Output Stream";
// fos.write(data.getBytes());
// fos.close();
// File f = new File("Data");
// if (f.mkdir()) {
// File f1 = new File(f.getAbsolutePath() + "/data.txt");
// f1.createNewFile();
// FileOutputStream fos = new FileOutputStream(f1);
// String data = "Hello New File from Output Stream";
// fos.write(data.getBytes());
//
// System.out.println("New Folder and File created");
//
// fos.close();
// }
}
public static void sortDirectory(File folder) {
for (File file : folder.listFiles()) {
if (file.isDirectory()) {
sortFile.put(file.lastModified(), file.getName());
sortDirectory(file);
} else {
// System.out.println(file.getName() + file.lastModified());
sortFile.put(file.lastModified(), file.getName());
}
}
}
public static void printDirectory(File folder) {
for (File file : folder.listFiles()) {
if (file.isDirectory()) {
System.out.println("---" + file.getName() + " Directory---(" + file.listFiles().length + ")");
printDirectory(file);
} else {
System.out.println(file.getName());
}
}
}
}