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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
package test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import com.nis.nmsclient.common.Contants;
import com.nis.nmsclient.util.DateUtil;
import com.nis.nmsclient.util.FileUtil;
import com.nis.nmsclient.util.FileWrUtil;
public class Test {
public static void main(String[] args) {
//method2();
//method1();
/*File file = new File("C:\\Documents and Settings\\zhenzhen\\桌面\\nmsdata\\test1");
long now = System.currentTimeMillis();
File[] files = file.listFiles();
for(File file2 : files){
System.out.println("========"+file2.getName());
}
System.out.println(System.currentTimeMillis()-now);
now = System.currentTimeMillis();
String[] fileNames = file.list();
for(String file2 : fileNames){
System.out.println("========"+file2);
}
System.out.println(System.currentTimeMillis()-now);*/
/*try {
long now = System.currentTimeMillis();
ProcessUtil.getProcessId("javaw.exe");
System.out.println(System.currentTimeMillis()-now);
} catch (Exception e) {
e.printStackTrace();
}*/
/*try {
FileUtils.copyDirectoryToDirectory(new File("D:\\temp\\test"), new File("D:\\temp\\t1"));
FileUtils.copyDirectory(new File("D:\\temp\\test"), new File("D:\\temp\\test2"));
File file = new File("D:\\temp\\tt\\temp");
if(file.getParentFile().canWrite()){
System.out.println("Yes");
}
String[] except = new String[3];
except[0]="D:\\temp\\test\\WebRoot";
except[1]="D:\\temp\\test\\t1.tar.gz";
except[2]="D:\\temp\\test\\src\\filemgr\\ZipUtil.java";
//new AgentCommand().backup(new File("D:\\temp\\test"), new File("D:\\temp\\t2"), except);
} catch (Exception e) {
e.printStackTrace();
}*/
/*String filepath = "";
if(filepath.startsWith("/") || (filepath.length()>3 && filepath.substring(1,3).equals(":\\"))){
System.out.println("ff");
}*/
/*File file = new File("D:\\temp");
File file2 = new File("D:\\temp\\test\\..");
System.out.println(file.compareTo(file2));
try{
System.out.println(file.getCanonicalPath() + "--" + file2.getCanonicalPath());
}catch (Exception e) {
// TODO: handle exception
}*/
try {
//ProcessUtil.runExec("D:/test.bat");
/*ProcessUtil.runExec("D:\\Program Files\\PLSQL Developer\\plsqldev.exe");
String cmd ="D:/Program Files/Navicat for MySQL/navicat.exe";
Runtime.getRuntime().exec("cmd /c " + cmd.replace(" ", "\" \""));
//ProcessUtil.runExec("D:/Program Files/feiq/飞秋FeiQ.exe");
String tempString = "0";
int length = tempString.split(":").length;
System.out.println(length);*/
/*Properties prop = System.getProperties();
for(Map.Entry<Object,Object> entry : prop.entrySet()){
System.out.println(entry.getKey()+"="+entry.getValue());
}*/
System.out.println(Contants.class.getClassLoader().getResource("myconfig.properties").getPath()) ;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void method1(){
long curDate = System.currentTimeMillis();
// 删除指定分钟之前的所有监测文件
File file = new File("C:/Documents and Settings/zhenzhen/桌面/nmsdata/test");
if (!file.exists()) {
return;
}
File[] dirs = FileUtil.getDirectoryArray(file);
if (dirs == null || dirs.length <= 0) {
return;
}
for (File dir : dirs) {
File[] files = FileUtil.getFilesEndWith(dir, ".csv");
if (files == null || files.length <= 0) {
return;
}
for (File f : files) {
long diff = DateUtil.getMinutesFromBeginToEnd(f.lastModified(), curDate);
if (f.exists() && diff > 1) {
f.delete();
}
}
}
System.out.println("=========method1 : " + (System.currentTimeMillis()-curDate));
}
public static void method2(){
try {
long curDate = System.currentTimeMillis();
List<String> arrayList = new ArrayList<String>();
// 删除指定分钟之前的所有监测文件
File file = new File("D:/test1");
if (!file.exists()) {
return;
}
File[] dirs = FileUtil.getDirectoryArray(file);
if (dirs == null || dirs.length <= 0) {
return;
}
for (File dir : dirs) {
File[] files = FileUtil.getFilesEndWith(dir, ".csv");
if (files == null || files.length <= 0) {
return;
}
for (File f : files) {
//arrayList.add(f.getAbsolutePath());
FileWrUtil.cfgFileAppender(new File("C:/Documents and Settings/zhenzhen/桌面/nmsdata/test.txt"), "utf-8", new String[]{f.getAbsolutePath()});
}
}
//String[] tmp = new String[arrayList.size()];
//FileWrUtil.cfgFileAppender(new File("C:/Documents and Settings/zhenzhen/桌面/nmsdata/test.txt"), "utf-8", arrayList.toArray(tmp));
System.out.println("=========method2 Write end : " + (System.currentTimeMillis()-curDate));
curDate = System.currentTimeMillis();
FileInputStream in = new FileInputStream(new File("C:/Documents and Settings/zhenzhen/桌面/nmsdata/test.txt"));
BufferedReader bReader = new BufferedReader(new InputStreamReader(in, Contants.charset));
String line = "";
List<File> arrList = new ArrayList<File>();
while ((line = bReader.readLine()) != null){
/*File file2 = new File(line);
if(file2.exists()){
file2.delete();
}*/
arrList.add(new File(line));
}
bReader.close();
in.close();
System.out.println("=========method2 : " + (System.currentTimeMillis()-curDate));
curDate = System.currentTimeMillis();
for(File file3 : arrList){
if(file3.exists()){
file3.delete();
}
}
System.out.println("=========method2 : " + (System.currentTimeMillis()-curDate));
} catch (Exception e) {
e.printStackTrace();
}
}
}
|