Guest User

Untitled

a guest
Nov 30th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. //Method025: Imports user acc settings from a file on a specified path.
  2. public void importFile() {
  3. //The file variable to be imported.
  4. File file;
  5.  
  6. try {
  7. //Used to access settings.
  8. TinyDB database = new TinyDB(getApplicationContext());
  9.  
  10. //Sets the file equal to the file found at the specified path.
  11. String strfilePath = database.getString("FilePath");
  12. file = new File(strfilePath);
  13.  
  14. //To be used to arrange the imported information.
  15. ArrayList<String> strAcc = new ArrayList<>();
  16. ArrayList<String> strUser = new ArrayList<>();
  17. ArrayList<String> strPass = new ArrayList<>();
  18. ArrayList<String> strAdditionalInfo = new ArrayList<>();
  19.  
  20. //To be used to store all the information for additional info variables. This is
  21. //due to its multi-line nature requiring a slightly different method of
  22. //importation, the other variables are expected to be one line.
  23. String strExtraInfo = "";
  24.  
  25. //Goes through the file and adds info to arrays for each corresponding variable.
  26. //If the line does not have an identifier, it assumes it to be an additional
  27. //info line, and will be processed later.
  28. try (BufferedReader br = new BufferedReader(new FileReader(file))) {
  29. String line;
  30.  
  31. String strLine = br.readLine();
  32. //Decodes the line from Base64 and converts it to a string.
  33. byte[] decodedContent = Base64.decode(strLine.getBytes(), Base64.DEFAULT);
  34. strLine = new String (decodedContent);
  35.  
  36. while ((line = br.readLine()) != null) {
  37. if (strLine.contains("[Acc]")) {
  38. strLine = strLine.replace("[Acc]","");
  39. strAcc.add(strLine);
  40. } else if (strLine.contains("[User]")) {
  41. strLine = strLine.replace("[User]", "");
  42. strUser.add(strLine);
  43. } else if (strLine.contains("[Pass]")) {
  44. strLine = strLine.replace("[Pass]", "");
  45. strPass.add(strLine);
  46. } else {
  47. strExtraInfo += strLine;
  48. }
  49. }
  50. }
Add Comment
Please, Sign In to add comment