Advertisement
Hakunin

Untitled

Nov 21st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. /**
  2. * Created by markort2815 on 21.11.17..
  3. */
  4. import java.io.*;
  5.  
  6. public class app {
  7. public static void main(String[] args) {
  8.  
  9. File f = new File("licence.bin");
  10.  
  11. if(!f.exists()){
  12. try {
  13. Settings def = new Settings();
  14. f.createNewFile();
  15. def.upisi("licence.bin");
  16. System.out.println("Datoteka kreirana!");
  17. } catch (IOException e) {
  18. e.printStackTrace();
  19. }
  20. }else {
  21. System.out.println("Datoteka vec postoji");
  22. Settings cit =null;
  23. cit = Settings.procitaj("licence.bin");
  24. System.out.println(cit);
  25. }
  26. }
  27. }
  28.  
  29. import java.io.*;
  30.  
  31. /**
  32. * Created by markort2815 on 21.11.17..
  33. */
  34. public class Settings implements Serializable {
  35. private String korisnickoime;
  36. private String licenca;
  37. private int vreme;
  38.  
  39. public Settings(String korisnickoime, String licenca, int vreme) {
  40. this.korisnickoime = korisnickoime;
  41. this.licenca = licenca;
  42. this.vreme = vreme;
  43. }
  44.  
  45. public Settings() {
  46. this.korisnickoime = "evaluate";
  47. this.licenca = "0000-0000-0000-0000";
  48. this.vreme = 1;
  49. }
  50.  
  51. public static Settings procitaj(String path){
  52. try {
  53. FileInputStream fileInputStream = new FileInputStream(path);
  54. ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
  55. Settings load = (Settings)objectInputStream.readObject();
  56. fileInputStream.close();
  57. objectInputStream.close();
  58. return load;
  59. }catch (IOException e){
  60. e.printStackTrace();
  61. return null;
  62. }catch (ClassNotFoundException e){
  63. e.printStackTrace();
  64. return null;
  65. }
  66. }
  67.  
  68. public void upisi(String path){
  69. try {
  70. FileOutputStream fileOutputStream = new FileOutputStream(path);
  71. ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
  72. objectOutputStream.writeObject(this);
  73. objectOutputStream.close();
  74. fileOutputStream.close();
  75. }catch (IOException e){
  76. e.printStackTrace();
  77. }
  78. }
  79.  
  80. @Override
  81. public String toString() {
  82. return "Settings{" +
  83. "korisnickoime='" + korisnickoime + '\'' +
  84. ", licenca='" + licenca + '\'' +
  85. ", vreme=" + vreme +
  86. '}';
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement