My program backs up specific data at a specific time interval. I want to make it possible to restore. The problem is that I don't know how to load data from a file. Inside the file, the data is separated by ;
. The recording goes to a file with the extension .txt
A snippet of code how data is written to a file:
ContentValues cv = new ContentValues();
cv.put("DlvDate", DlvDate);
cv.put("PayDate", PayDate);
cv.put("DocType", DocType);
cv.put("Cust", Cust);
cv.put("PaymMode", PaymMode);
cv.put("PaymTerm", PaymTerm);
cv.put("PriceGroup", PriceGroup);
cv.put("CreatedDateTime", CreatedDateTime);
cv.put("Note", Note);
if (_id != 0) {
GlobalVars.db.update("SalesTable", cv, "_id = ?", new String[]{String.valueOf(_id)});
} else {
_id = GlobalVars.db.insert("SalesTable", null, cv);
}
File sFile = new File(GlobalVars.ArchiveDir + "/" + String.valueOf(_id) + ".txt");
BufferedWriter br;
try {
br = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sFile), "windows-1251"));
br.write(this.salesStr() + "\r\n");
br.close();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String sLine;
CustTable ct = new CustTable(this.Cust);
Cursor cSalesLine = GlobalVars.db.rawQuery("select * from SalesLine where SalesId = ?",
new String[]{String.valueOf(this._id)});
sLine = this.Cust //1
+ ";"
+ this.DocType //2
+ ";"
+ ct.PaymTerm //3
+ ";"
+ ct.PaymMode //4
+ ";"
+ GlobalVars.dateSQLtoLocal(this.DlvDate) //5
+ ";"
+ this.SalesTime //6
+ ";"
+ GlobalVars.dateSQLtoLocal(this.PayDate) //7
+ ";"
+ ct.PriceGroup //8
+ ";"
+ this.Note //9
+ ";;"
+ this.CreatedDateTime //11
+ ";"
+ this.CustOrderNo
+ "&"
+ ";";
cSalesLine.moveToFirst();
while (!cSalesLine.isAfterLast()) {
sLine += cSalesLine.getString(cSalesLine.getColumnIndex("Invent"))
+ ";"
+ cSalesLine.getString(cSalesLine.getColumnIndex("Qty"))
+ ";"
+ ";";
cSalesLine.moveToNext();
}
return sLine.substring(0, sLine.length() - 1);