summaryrefslogtreecommitdiff
path: root/src/ConfigFile.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ConfigFile.java')
-rw-r--r--src/ConfigFile.java96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/ConfigFile.java b/src/ConfigFile.java
new file mode 100644
index 0000000..b3c380d
--- /dev/null
+++ b/src/ConfigFile.java
@@ -0,0 +1,96 @@
+
+package src;
+
+/**
+ *
+ * @author przem
+ */
+
+import java.io.FileWriter;
+import java.io.File;
+import java.io.IOException;
+import java.io.FileNotFoundException; // Import this class to handle errors
+import java.util.Scanner;
+import java.util.*;
+
+public class ConfigFile {
+ public String userDir="", userHome="", osName="", osVersion="", jvmVersion="";
+ String name = "/kopieckreta.txt";
+ public ConfigFile() throws IOException{
+ for (Map.Entry<?,?> e : System.getProperties().entrySet()) {
+ //System.out.println(String.format("%s = %s", e.getKey(), e.getValue()));
+ if (e.getKey().equals("user.dir")) {
+ userDir=String.format("%s", e.getValue());
+ }
+ if (e.getKey().equals("user.home")) {
+ userHome=String.format("%s", e.getValue());
+
+ }
+ if (e.getKey().equals("os.name")) {
+ osName=String.format("%s", e.getValue());
+
+ }
+ if (e.getKey().equals("os.version")) {
+ osVersion=String.format("%s", e.getValue());
+
+ }
+ if (e.getKey().equals("java.vm.version")) {
+ jvmVersion=String.format("%s", e.getValue());
+
+ }
+ }
+
+
+ File file=new File (userHome+name);
+ if (file.createNewFile()){
+ System.out.println("Plik zostal utworzony");
+ try {
+ FileWriter myWriter = new FileWriter(userHome+name);
+ myWriter.write("1");
+ myWriter.close();
+ System.out.println("Successfully wrote to the file.");
+ } catch (IOException e) {
+ System.out.println("An error occurred.");
+ e.printStackTrace();
+ }
+ }
+ else {
+ System.out.println("Plik istnieje");
+ }
+ }
+ public void save(boolean b){
+ String s="";
+ try {
+ FileWriter myWriter = new FileWriter(userHome+name);
+ if (b) s="1";
+ else s="0";
+ myWriter.write(s);
+ myWriter.close();
+ System.out.println("Successfully wrote to the file.");
+ } catch (IOException e) {
+ System.out.println("An error occurred.");
+ e.printStackTrace();
+ }
+ }
+ public boolean load() {
+ String data = "";
+ boolean r =false;
+ try {
+ File myObj = new File(userHome+name);
+ Scanner myReader = new Scanner(myObj);
+ while (myReader.hasNextLine()) {
+ data = myReader.nextLine();
+ System.out.println(data);
+ }
+ myReader.close();
+ } catch (FileNotFoundException e) {
+ System.out.println("An error occurred.");
+ e.printStackTrace();
+ }
+
+ if (data.equals("1")) r=true;
+
+ return r;
+ }
+
+}