-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexampleConverter.java
More file actions
78 lines (69 loc) · 1.84 KB
/
exampleConverter.java
File metadata and controls
78 lines (69 loc) · 1.84 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
import java.io.*;
import java.util.ArrayList;
import java.util.List;
class Scratch
{
private static final List<String> sitesList = new ArrayList<>();
private static final List<String> transformedSitesList = new ArrayList<>();
public static void main(final String[] args) throws InterruptedException
{
readSitesFromFile("data/originalSites.txt");
convertListToScenarioExample(sitesList);
createEmptyFile("data/convertedSites.txt");
saveSitesToFile("data/convertedSites.txt");
}
private static void readSitesFromFile(final String filePath)
{
try
{
final FileReader reader = new FileReader(filePath);
final BufferedReader bufferedReader = new BufferedReader(reader);
String line;
while ((line = bufferedReader.readLine()) != null)
{
sitesList.add(line.toString());
}
reader.close();
}
catch (final IOException e)
{
e.printStackTrace();
}
}
private static void convertListToScenarioExample(final List<String> siteList)
{
for (final String site : sitesList)
{
transformedSitesList.add("| " + site + " |");
}
}
private static void createEmptyFile(final String filename)
{
try
{
final File newTextFile = new File(filename);
new FileWriter(newTextFile, false).close();
} catch (final IOException iox)
{
iox.printStackTrace();
}
}
private static void saveSitesToFile(final String filePath) throws InterruptedException
{
for (final String site : transformedSitesList)
{
System.out.println(site + '\n');
try
{
final File newTextFile = new File(filePath);
final FileWriter fw = new FileWriter(newTextFile, true);
fw.write(site + '\n');
fw.close();
}
catch (final IOException iox)
{
iox.printStackTrace();
}
}
}
}