-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoggerSigma2016.java
More file actions
52 lines (40 loc) · 1.38 KB
/
LoggerSigma2016.java
File metadata and controls
52 lines (40 loc) · 1.38 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
package org.firstinspires.ftc.teamcode;
import android.os.Environment;
import android.util.Log;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class LoggerSigma2016 {
public PrintWriter printWriter;
public LoggerSigma2016(String fileName) throws FileNotFoundException {
if (isExternalStorageWritable() == false)
{
System.out.println("No valid external storage found!");
System.exit(0);
}
String logFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/ctu_log/";
try {
File path = new File(logFilePath);
if (!path.exists()) {
path.mkdirs();
}
} catch (Exception e) {
Log.e("Log file path creation", e.getMessage());
}
printWriter = new PrintWriter(logFilePath + fileName);
}
public void logLine(String sLine) {
printWriter.println(sLine);
}
public void close() {
printWriter.close();
}
/* Checks if external storage is available for read and write */
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
}