-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFiles.java
More file actions
111 lines (90 loc) · 2.39 KB
/
Copy pathFiles.java
File metadata and controls
111 lines (90 loc) · 2.39 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
106
107
108
109
110
111
import java.io.*;
import java.util.Date;
/**
*
*
* @version 1.0 Jun 2018
* @author Amanda Camacho,
* Benjamin Amos <benjamin.oxi@gmail.com>
*/
//Maybe serializable
public class Files{
private String fileName;
private byte[] content;
private Date date;
private String path;
/**
* Constructs a File object.
* @param file path
*/
public Files(String path){
File newFile = new File(path);
try {
byte[] bFile = new byte[(int) newFile.length()];
BufferedInputStream into= new BufferedInputStream(new FileInputStream(newFile));
into.read(bFile,0,bFile.length);
into.close();
this.content=bFile;
} catch(Exception e) {
System.out.println("Archivo no encontrado.");
}
this.path = path;
this.fileName= newFile.getName();
}
/*###############################################################################*/
/* GETERS */
/**
* Return a file name
* @throws file name
*/
public String getFileName(){
return this.fileName;
}
/**
* Return a file Path
* @throws file path
*/
public String getFilePath(){
return this.path;
}
/**
* Return a file date
* @throws file date
*/
public Date getDate(){
return this.date;
}
/**
* Return a file content
* @throws file content
*/
public byte[] getcontent(){
return this.content;
}
/**
* Return a file date
* @throws file date
*/
public String fileToString(){
try{
if (this.content!= null){
String str = new String(content, "UTF_8");
return (str);
}
}catch (UnsupportedEncodingException uee){
System.out.println("Archivo: "+ uee.getMessage());
}
return null;
}
public static void main(String[] args) {
System.out.println("Archivo a abrir: " +args[0]);
Files f = new Files(args[0]);
System.out.println(f.getFileName());
System.out.println(f.getFilePath());
System.out.println("\u001B[31m"+f.getFileName()+"no existe.");
System.out.print("\u001B[0m");
if (f != null) {
System.out.println(f.toString());
}
}
}