Guest User

Untitled

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