Advertisement
Guest User

Untitled

a guest
Nov 24th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. import java.io.BufferedWriter;
  2. import java.io.DataInputStream;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.io.PrintWriter;
  8.  
  9. /**
  10. * @author Reece
  11. *
  12. **/
  13.  
  14. public class SettingHandler {
  15.  
  16. public static String LocationA = System.getenv("USERPROFILE") + "/RS/LoginUsername.txt";
  17. public static String LocationB = System.getenv("USERPROFILE") + "/RS/LoginPassword.txt";
  18.  
  19.  
  20. public static String[] username = { "Username: " + Loader.username };
  21. public static String[] password = { "Password: "+Loader.password };
  22.  
  23. public static void createFile() {
  24. System.out.print("Attempting to create file");
  25. File file = new File(LocationA);
  26. File file1 = new File(LocationB);
  27. if (!file.exists() || !file1.exists())
  28. try {
  29. file.createNewFile();
  30. file1.createNewFile();
  31. defaultsettings();
  32. saveUsername();
  33. savePassword();
  34. } catch (IOException e) {
  35. e.printStackTrace();
  36. }
  37. }
  38.  
  39. private static void defaultsettings() {
  40. Loader.username = "";
  41. Loader.password = "";
  42. }
  43.  
  44. public static void load() {
  45. try {
  46. File file = new File(LocationA);
  47. File file1 = new File(LocationB);
  48. if (!file.exists() || !file1.exists()) {
  49. return;
  50. }
  51.  
  52. DataInputStream inA = new DataInputStream(new FileInputStream(file));
  53. DataInputStream inB = new DataInputStream(new FileInputStream(file1));
  54. Loader.username = inA.readLine();
  55. Loader.password = inB.readLine();
  56. inA.close();
  57. inB.close();
  58. System.out.print(username.length + " settings has successfully been loaded.");
  59.  
  60. } catch(IOException e) {
  61. e.printStackTrace();
  62. }
  63. }
  64.  
  65.  
  66. public static void saveUsername() {
  67. try {
  68. PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(LocationA)));
  69. out.flush();
  70. out.println(Loader.username);
  71. out.close();
  72. System.out.print(username.length + " infomation has been saved.");
  73. } catch (Exception e) {
  74. e.printStackTrace();
  75. }
  76. }
  77.  
  78. public static void savePassword() {
  79. try {
  80. PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(LocationB)));
  81. out.flush();
  82. out.println(Loader.password);
  83. out.close();
  84. System.out.print(password.length + " infomation has been saved.");
  85. } catch (Exception e) {
  86. e.printStackTrace();
  87. }
  88. }
  89.  
  90. public static boolean FileExists() {
  91. File file = new File(LocationA);
  92. File file1 = new File(LocationB);
  93. if (file.exists() || file1.exists())
  94. return true;
  95. else
  96. return false;
  97. }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement