-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReplaysController.java
More file actions
89 lines (81 loc) · 2.05 KB
/
ReplaysController.java
File metadata and controls
89 lines (81 loc) · 2.05 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
84
85
86
87
88
89
package game;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Date;
public class ReplaysController {
private RandomAccessFile file;
/**
* Create file for saving with extend .save
*/
public void createResultFile() {
try {
file = new RandomAccessFile(new File(new Date().toString()+".save"), "rw");
} catch (FileNotFoundException e) {
System.out.println("File was not created!");
}
}
/**
* @param fileName name of opening file
*/
public void openResultFile(String fileName) {
try {
file = new RandomAccessFile(new File(fileName), "rw");
} catch (FileNotFoundException e) {
System.out.println("File was not opened!");
}
}
public void saveChar(char r)
{
try {
file.writeChar(r);
} catch (IOException e) {
System.out.println("Error of writing!");
}
}
public char loadChar()
{
try {
if (file.getFilePointer() == file.length()) {
return (char) -1;
}
return file.readChar();
} catch (IOException e) {
System.out.println("Error of reading!");
}
return (char) -1;
}
/**
* Close results file
*/
public void finalize() {
try {
file.close();
} catch (IOException e) {
System.out.println("File was not closed!");
}
}
/**
*
* @return directory content(but only items ".save")
*/
public static String[] folderContent() {
File folder = new File(".");
File[] listOfFiles = folder.listFiles();
int length = 0;
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].getName().contains(".save")) {
length++;
}
}
String[] content = new String[length];
for (int i = 0, j = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].getName().contains(".save")) {
content[j] = listOfFiles[i].getName();
j++;
}
}
return content;
}
}