Advertisement
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;
- /**
- * @author Reece
- *
- **/
- public class SettingHandler {
- 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 file");
- File file = new File(LocationA);
- File file1 = new File(LocationB);
- if (!file.exists() || !file1.exists())
- try {
- file.createNewFile();
- file1.createNewFile();
- defaultsettings();
- saveUsername();
- savePassword();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- private static void defaultsettings() {
- Loader.username = "";
- Loader.password = "";
- }
- 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 + " infomation 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 + " infomation 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement