@@ -48,173 +48,6 @@ public boolean accept(File current, String name) {
48
48
}
49
49
});
50
50
// System.out.println(Arrays.toString(directories));
51
- <<<<<<< HEAD
52
- return directories ;
53
- }
54
-
55
- public static String readFile2Str (String fpath ) {
56
- String content = "" ;
57
- try {
58
- content = new String (Files .readAllBytes (Paths .get (fpath )));
59
- } catch (IOException e ) {
60
- e .printStackTrace ();
61
- }
62
- return content ;
63
-
64
- }
65
-
66
- public static boolean renameDir (String dirPath , String newDirName ) {
67
-
68
- File dir = new File (dirPath );
69
- if (!dir .isDirectory ()) {
70
- System .err .println ("There is no directory @ given path" );
71
- return false ;
72
- } else {
73
- File newDir = new File (dir .getParent () + "/" + newDirName );
74
- dir .renameTo (newDir );
75
- }
76
- return true ;
77
- }
78
-
79
- public static Boolean writeStr2File (String wStr , String fPath ) {
80
- try {
81
- Files .write (Paths .get (fPath ), wStr .getBytes ());
82
- } catch (IOException e ) {
83
- // TODO Auto-generated catch block
84
- e .printStackTrace ();
85
- return false ;
86
- }
87
- return true ;
88
- }
89
-
90
- public static boolean deleteDirectory (String dirPath ) {
91
- File directoryToBeDeleted = new File (dirPath );
92
- File [] allContents = directoryToBeDeleted .listFiles ();
93
- if (allContents != null ) {
94
- for (File file : allContents ) {
95
- deleteDirectory (file .getAbsolutePath ());
96
- }
97
- }
98
- return directoryToBeDeleted .delete ();
99
- }
100
-
101
- public static void copyFolder (Path srcDirStr , Path destDirStr ) {
102
- File source = new File (srcDirStr .toString ());
103
- File dest = new File (destDirStr .toString ());
104
- try {
105
- FileUtils .copyDirectory (source , dest );
106
- } catch (IOException e ) {
107
- e .printStackTrace ();
108
- }
109
- }
110
-
111
- public static void writeStringToFile (String filePath , String dataStr ) {
112
- BufferedWriter bufferedWriter = null ;
113
- try {
114
- File file = new File (filePath );
115
- if (!file .exists ()) {
116
- file .createNewFile ();
117
- }
118
- Writer writer = new FileWriter (file );
119
- bufferedWriter = new BufferedWriter (writer );
120
- bufferedWriter .write (dataStr );
121
- } catch (IOException e ) {
122
- e .printStackTrace ();
123
- } finally {
124
- try {
125
- if (bufferedWriter != null )
126
- bufferedWriter .close ();
127
- } catch (Exception e ) {
128
- System .out .println ("Write file error!" );
129
- e .printStackTrace ();
130
- }
131
- }
132
- }
133
-
134
- public static String readStringFromFile (String filePath ) {
135
- try {
136
- File file = new File (filePath );
137
- if (file .isFile () && file .exists ()) {
138
- InputStreamReader read = new InputStreamReader (new FileInputStream (file ));
139
- BufferedReader bufferedReader = new BufferedReader (read );
140
- StringBuilder stringBuilder = new StringBuilder ();
141
- String line = null ;
142
- String ls = System .getProperty ("line.separator" );
143
- while ((line = bufferedReader .readLine ()) != null ) {
144
- stringBuilder .append (line );
145
- stringBuilder .append (ls );
146
- }
147
-
148
- // delete the last new line separator
149
- stringBuilder .deleteCharAt (stringBuilder .length () - 1 );
150
- bufferedReader .close ();
151
-
152
- String content = stringBuilder .toString ();
153
- return content ;
154
- } else {
155
- System .out .printf ("File not found! %s\n " , filePath );
156
- }
157
- } catch (Exception e ) {
158
- System .out .println ("Read file error!" );
159
- e .printStackTrace ();
160
- }
161
- return null ;
162
- }
163
-
164
- public static List <String > readFileToStrList (String filePath ) {
165
- ArrayList <String > strList = new ArrayList <String >();
166
- try {
167
- if (!new File (filePath ).exists ()) {
168
- System .out .println ("File not exists! " + filePath );
169
- return null ;
170
- }
171
- BufferedReader reader = new BufferedReader (new FileReader (filePath ));
172
- String line = reader .readLine ();
173
- while (line != null ) {
174
- strList .add (line );
175
- line = reader .readLine ();
176
- }
177
- reader .close ();
178
- } catch (FileNotFoundException e ) {
179
- // TODO Auto-generated catch block
180
- System .out .println ("filePath : " + filePath );
181
- e .printStackTrace ();
182
- } catch (IOException e ) {
183
- // TODO: handle exception
184
- System .out .println ("filePath : " + filePath );
185
- e .printStackTrace ();
186
- }
187
- return strList ;
188
- }
189
-
190
- public static void createFolder (String dirStr , Boolean deleteIfExist ) {
191
- File dir = new File (dirStr );
192
- if (deleteIfExist && dir .exists ()) {
193
- deleteDirectory (dir .getAbsolutePath ());
194
- dir .mkdirs ();
195
- } else if (!dir .exists ()) {
196
- dir .mkdirs ();
197
- }
198
- }
199
-
200
- public static boolean deleteDirectory (File directoryToBeDeleted ) {
201
- File [] allContents = directoryToBeDeleted .listFiles ();
202
- if (allContents != null ) {
203
- for (File file : allContents ) {
204
- deleteDirectory (file );
205
- }
206
- }
207
- return directoryToBeDeleted .delete ();
208
- }
209
-
210
- public static List <String > findFilePathofSpecifcTypeRecusive (String tarDir , String extension ) {
211
-
212
- List <String > pathList = new ArrayList <String >();
213
- try {
214
- Files .walk (Paths .get (tarDir )).filter (Files ::isRegularFile ).forEach ((f ) -> {
215
- String filepath = f .toString ();
216
- if (filepath .endsWith (extension ))
217
- =======
218
51
return directories ;
219
52
}
220
53
@@ -401,7 +234,6 @@ public static List<File> findFilePathofSpecifcTypeRecusive(String tarDir, String
401
234
Files .walk (Paths .get (tarDir )).filter (Files ::isRegularFile ).forEach ((f ) -> {
402
235
String filepath = f .toString ();
403
236
if (filepath .endsWith (extension ))
404
- >>>>>>> 98f 658f 3 ed0bbc9974f52192ded7dd9a43b7f5d7
405
237
// System.out.println(file + " found!");
406
238
fileList .add (new File (filepath ));
407
239
});
0 commit comments