Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by markort2815 on 21.11.17..
- */
- import java.io.*;
- public class app {
- public static void main(String[] args) {
- File f = new File("licence.bin");
- if(!f.exists()){
- try {
- Settings def = new Settings();
- f.createNewFile();
- def.upisi("licence.bin");
- System.out.println("Datoteka kreirana!");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }else {
- System.out.println("Datoteka vec postoji");
- Settings cit =null;
- cit = Settings.procitaj("licence.bin");
- System.out.println(cit);
- }
- }
- }
- import java.io.*;
- /**
- * Created by markort2815 on 21.11.17..
- */
- public class Settings implements Serializable {
- private String korisnickoime;
- private String licenca;
- private int vreme;
- public Settings(String korisnickoime, String licenca, int vreme) {
- this.korisnickoime = korisnickoime;
- this.licenca = licenca;
- this.vreme = vreme;
- }
- public Settings() {
- this.korisnickoime = "evaluate";
- this.licenca = "0000-0000-0000-0000";
- this.vreme = 1;
- }
- public static Settings procitaj(String path){
- try {
- FileInputStream fileInputStream = new FileInputStream(path);
- ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
- Settings load = (Settings)objectInputStream.readObject();
- fileInputStream.close();
- objectInputStream.close();
- return load;
- }catch (IOException e){
- e.printStackTrace();
- return null;
- }catch (ClassNotFoundException e){
- e.printStackTrace();
- return null;
- }
- }
- public void upisi(String path){
- try {
- FileOutputStream fileOutputStream = new FileOutputStream(path);
- ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
- objectOutputStream.writeObject(this);
- objectOutputStream.close();
- fileOutputStream.close();
- }catch (IOException e){
- e.printStackTrace();
- }
- }
- @Override
- public String toString() {
- return "Settings{" +
- "korisnickoime='" + korisnickoime + '\'' +
- ", licenca='" + licenca + '\'' +
- ", vreme=" + vreme +
- '}';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement