-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIOFile.java
More file actions
58 lines (48 loc) · 1.41 KB
/
IOFile.java
File metadata and controls
58 lines (48 loc) · 1.41 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
public class IOFile
{
private final String fileName = "Example.txt";
public IOFile(String fileName)
{
this.fileName = fileName;
}
public void createFile()
{
try{
private OutputStreamWriter file = new OutputStreamWriter(openFileOutput(file_name, Context.MODE_PRIVATE));
}catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
}
public void writeFile(String text) {
try{
file.write(text);
file.close();
}catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
}
public String readFile() {
String result = "";
String currentLineFile;
try {
InputStream file = openFileInput(file_name);
if (file != null) {
InputStreamReader reader = new InputStreamReader(file);
BufferedReader buff = new BufferedReader(reader);
while ((currentLineFile = buff.readLine()) != null) {
result += currentLineFile;
}
file.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
}