-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriter.pde
More file actions
84 lines (72 loc) · 1.67 KB
/
Copy pathWriter.pde
File metadata and controls
84 lines (72 loc) · 1.67 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
import java.io.File;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class Writer {
PApplet dad;
BufferedWriter out;
Writer(PApplet dad)
{
this.dad = dad;
}
public void overWrite(String name, String[] content)
{
dad.saveStrings(name, content);
}
public void writeAt(String name, String content)
{
File f = new File(dad.dataPath(name));
if (!f.exists())
{
createFile(f);
}
try
{
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f, true)));
out.println(content);
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void writeAt(String name, String[] content)
{
File f = new File(dad.dataPath(name));
if (!f.exists())
{
createFile(f);
}
try
{
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f, true)));
for (String s : content)
{
out.println(s);
}
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
/**
* Creates a new file including all subfolders
*/
private void createFile(File f)
{
File parentDir = f.getParentFile();
try
{
parentDir.mkdirs();
f.createNewFile();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}