-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsavingDB.java
More file actions
46 lines (33 loc) · 1.43 KB
/
savingDB.java
File metadata and controls
46 lines (33 loc) · 1.43 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
public void saveLocalDB() {
try {
String timeStamp = new SimpleDateFormat("dd-MM-yyyy_HHmm").format(Calendar.getInstance().getTime());
final String inFileName = "/data/data/com.example.MyApplication/databases/databaseName";
File dbFile = new File(inFileName);
if(dbFile.exists()) {
FileInputStream fis = new FileInputStream(dbFile);
String dirPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/databases/";
String outFileName = dirPath + timeStamp + "_database.db";
File dir = new File(dirPath);
if (!dir.exists()) {
dir.mkdirs();
}
// Open the empty db as the output stream
OutputStream output = new FileOutputStream(outFileName);
// Transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
// Close the streams
output.flush();
output.close();
fis.close();
}
else Log.e(TAG, "Database file not found");
}
catch (Exception e)
{
Log.e(TAG, e.getMessage());
}
}