Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedWriter;
- import java.io.DataInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- /**
- * @author Reece
- * Creates, Saves, Loads Login infomation for quick-logins
- **/
- public class QuickLoginSaving {
- public static String LocationA = System.getenv("USERPROFILE") + "/RS/LoginUsername.txt";
- public static String LocationB = System.getenv("USERPROFILE") + "/RS/LoginPassword.txt";
- public static String[] username = { "Username: " + Loader.username };
- public static String[] password = { "Password: "+Loader.password };
- public static void CreateFile() {
- System.out.print("Attempting to create files");
- File outputFolder = new File(""+System.getenv("USERPROFILE")+"/RS");
- if (!outputFolder.exists()) {
- if (outputFolder.mkdir()) {
- } else {
- System.out.println("Failed to create directory!");
- }
- }
- File file = new File(LocationA);
- File file1 = new File(LocationB);
- if (!file.exists() || !file1.exists())
- try {
- file.createNewFile();
- file1.createNewFile();
- saveUsername();
- savePassword();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static void load() {
- try {
- File file = new File(LocationA);
- File file1 = new File(LocationB);
- if (!file.exists() || !file1.exists()) {
- return;
- }
- DataInputStream inA = new DataInputStream(new FileInputStream(file));
- DataInputStream inB = new DataInputStream(new FileInputStream(file1));
- Loader.username = inA.readLine();
- Loader.password = inB.readLine();
- inA.close();
- inB.close();
- System.out.print(username.length + " settings has successfully been loaded.");
- } catch(IOException e) {
- e.printStackTrace();
- }
- }
- public static void saveUsername() {
- try {
- PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(LocationA)));
- out.flush();
- out.println(Loader.username);
- out.close();
- System.out.print(username.length + " Username data has been saved.");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void savePassword() {
- try {
- PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(LocationB)));
- out.flush();
- out.println(Loader.password);
- out.close();
- System.out.print(password.length + " Password data has been saved.");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static boolean FileExists() {
- File file = new File(LocationA);
- File file1 = new File(LocationB);
- if (file.exists() || file1.exists())
- return true;
- else
- return false;
- }
- }
Add Comment
Please, Sign In to add comment