public class DBDAO { protected SQLiteDatabase database; private DatabaseHelper dbHelper; private DataBaseHelper_FR dbHelper_FR; private Context mContext; public DBDAO(Context context) { this.mContext = context; dbHelper = new DatabaseHelper(mContext); open(); } public void open() throws SQLException { if(fileExists(mContext, "language.txt")) { lang = main.ReadFile(); } else { main.WriteFile("English"); lang = "English"; } if (lang == "English") { if (dbHelper == null) dbHelper = new DatabaseHelper(mContext); database = dbHelper.getWritableDatabase(); } else if (lang == "France") { if (dbHelper_FR == null) dbHelper_FR = new DataBaseHelper_FR(mContext); database = dbHelper_FR.getWritableDatabase(); } } public boolean fileExists(Context context, String filename) { File file = context.getFileStreamPath(filename); if (file == null || !file.exists()) { return false; } return true; } // write text to file public void WriteFile(String writeString) { // add-write text into file try { FileOutputStream fileout = mContext.openFileOutput("language.txt", mContext.MODE_PRIVATE); OutputStreamWriter outputWriter = new OutputStreamWriter(fileout); outputWriter.write(writeString); outputWriter.close(); } catch (Exception e) { e.printStackTrace(); } } // Read text from file public String ReadFile() { // reading text from file String s = ""; try { FileInputStream fileIn = mContext.openFileInput("language.txt"); InputStreamReader InputRead = new InputStreamReader(fileIn); char[] inputBuffer = new char[100]; int charRead; while ((charRead = InputRead.read(inputBuffer)) > 0) { // char to string conversion String readstring = String .copyValueOf(inputBuffer, 0, charRead); s += readstring; } InputRead.close(); } catch (Exception e) { e.printStackTrace(); } return s; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)