-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile_Details_Reader.java
More file actions
63 lines (46 loc) · 1.53 KB
/
File_Details_Reader.java
File metadata and controls
63 lines (46 loc) · 1.53 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
package com.cucumber;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
public class File_Details_Reader {
public static void main(String[] args) throws IOException {
File dir = new File("C:\\workspace\\VehicleDetails");
String fileName = "";
for (File file : dir.listFiles()) {
fileName = file.getName();
System.out.println("File Name: " + fileName);
System.out.println("File Size: " + file.length());
System.out.println("File Mime Type: " + Files.probeContentType(file.toPath()));
System.out.println("File Extension: " + fileName.substring(fileName.lastIndexOf(".") + 1));
System.out.println("file path " + file.getPath());
if ("csv".equals(fileName.substring(fileName.lastIndexOf(".") + 1))) {
BufferedReader br = null;
String line = "";
String cvsSplitBy = ",";
try {
br = new BufferedReader(new FileReader(file.getPath()));
while ((line = br.readLine()) != null) {
// use comma as separator
String[] vehicleDtls = line.split(cvsSplitBy);
System.out.println("vehicle number " + vehicleDtls[0]);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}
}