4
4
import java .util .Map ;
5
5
6
6
public class WritePathResult {
7
+ private static int count = 0 ;
8
+
9
+ public static void ergodicDir (File dir , PrintWriter targetFilePW , Map <String , String > API2IndexMap ) throws IOException {
7
10
8
- public static void ergodicDir (File dir , File targetFile , Map <String , String > API2IndexMap ) throws IOException {
9
- if (targetFile .exists ()) {
10
- targetFile .delete ();
11
- }
12
11
if (dir .isDirectory ()){
13
12
for (File file : dir .listFiles ()){
14
13
if (file .isDirectory ()){
15
- ergodicDir (file , targetFile , API2IndexMap );
14
+ System .out .println ("ergodicDir..." );
15
+ ergodicDir (file , targetFilePW , API2IndexMap );
16
16
}
17
17
if (file .isFile () && file .getName ().endsWith ("dot" )){
18
- writePath (file , targetFile , API2IndexMap );
18
+ System .out .println ("processing " + ++count + " data" );
19
+ writePath (file , targetFilePW , API2IndexMap );
19
20
}
20
21
}
21
22
}
22
23
else {
23
24
if (dir .isFile () && dir .getName ().endsWith ("dot" )){
24
- writePath (dir , targetFile , API2IndexMap );
25
+ System .out .println ("processing " + ++count + " data" );
26
+ writePath (dir , targetFilePW , API2IndexMap );
25
27
}
26
28
}
27
29
}
28
30
29
- public static void writePath (File groumFile , File targetFile , Map <String , String > API2IndexMap ) throws IOException {
31
+ private static void writePath (File groumFile , PrintWriter targetFilePW , Map <String , String > API2IndexMap ) throws IOException {
30
32
ConstructGroum CG = new ConstructGroum ();
31
33
Groum groum = CG .constructGroum (groumFile .getAbsolutePath (), API2IndexMap );
32
34
Map <String , GroumNode > nodeMap = groum .getNodeMap ();
@@ -35,22 +37,28 @@ public static void writePath(File groumFile, File targetFile, Map<String, String
35
37
startList = new ArrayList <>();
36
38
startList .add (id );
37
39
List <List <String >> outList = GetPath .getAllPath (groum , startList , 4 );
38
- writeFile (outList , targetFile );
40
+ writeFile (outList , targetFilePW );
39
41
}
40
42
}
41
43
42
- public static void writeFile (List <List <String >> outList , File target ) throws IOException {
43
- if (!target .exists ()) {
44
- target .createNewFile ();
44
+ private static String convertListToString (List <String > list ) {
45
+ StringBuilder sB = new StringBuilder ();
46
+ boolean ifStarted = false ;
47
+ for (String item : list ) {
48
+ if (ifStarted ) {
49
+ sB .append ("," );
50
+ }
51
+ sB .append (item );
52
+ if (!ifStarted ) ifStarted = true ;
45
53
}
46
- FileWriter fileWriter = new FileWriter (target , true );
47
- PrintWriter pw = new PrintWriter (fileWriter );
54
+ return sB .toString ();
55
+ }
56
+
57
+ private static void writeFile (List <List <String >> outList , PrintWriter targetFilePW ) throws IOException {
58
+ String tempStr = null ;
48
59
for (List <String > path : outList ) {
49
- pw .println (path .toString ());
60
+ tempStr = convertListToString (path );
61
+ targetFilePW .println (tempStr );
50
62
}
51
- pw .flush ();
52
- fileWriter .flush ();
53
- pw .close ();
54
- fileWriter .close ();
55
63
}
56
64
}
0 commit comments