Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Method025: Imports user acc settings from a file on a specified path.
- public void importFile() {
- //The file variable to be imported.
- File file;
- try {
- //Used to access settings.
- TinyDB database = new TinyDB(getApplicationContext());
- //Sets the file equal to the file found at the specified path.
- String strfilePath = database.getString("FilePath");
- file = new File(strfilePath);
- //To be used to arrange the imported information.
- ArrayList<String> strAcc = new ArrayList<>();
- ArrayList<String> strUser = new ArrayList<>();
- ArrayList<String> strPass = new ArrayList<>();
- ArrayList<String> strAdditionalInfo = new ArrayList<>();
- //To be used to store all the information for additional info variables. This is
- //due to its multi-line nature requiring a slightly different method of
- //importation, the other variables are expected to be one line.
- String strExtraInfo = "";
- //Goes through the file and adds info to arrays for each corresponding variable.
- //If the line does not have an identifier, it assumes it to be an additional
- //info line, and will be processed later.
- try (BufferedReader br = new BufferedReader(new FileReader(file))) {
- String line;
- String strLine = br.readLine();
- //Decodes the line from Base64 and converts it to a string.
- byte[] decodedContent = Base64.decode(strLine.getBytes(), Base64.DEFAULT);
- strLine = new String (decodedContent);
- while ((line = br.readLine()) != null) {
- if (strLine.contains("[Acc]")) {
- strLine = strLine.replace("[Acc]","");
- strAcc.add(strLine);
- } else if (strLine.contains("[User]")) {
- strLine = strLine.replace("[User]", "");
- strUser.add(strLine);
- } else if (strLine.contains("[Pass]")) {
- strLine = strLine.replace("[Pass]", "");
- strPass.add(strLine);
- } else {
- strExtraInfo += strLine;
- }
- }
- }
Add Comment
Please, Sign In to add comment