Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author aldui
- */
- public class Jedinacek {
- private static Jedinacek instance;
- int counter;
- private Jedinacek() {
- DataInputStream input;
- try {
- input = new DataInputStream(new FileInputStream("counter.dat"));
- counter = input.readInt();
- input.close();
- } catch (Exception ex) {
- try {
- FileOutputStream fos = new FileOutputStream("counter.dat");
- DataOutputStream dos = new DataOutputStream(fos);
- counter = 0;
- dos.writeInt(counter);
- dos.close();
- } catch (IOException ex1) {
- Logger.getLogger(Jedinacek.class.getName()).log(Level.SEVERE, null, ex1);
- }
- }
- }
- public static Jedinacek getInstance() {
- if (instance == null) {
- instance = new Jedinacek();
- }
- return instance;
- }
- public void addOne() {
- counter += 1;
- try {
- FileOutputStream fos = new FileOutputStream("counter.dat");
- DataOutputStream dos = new DataOutputStream(fos);
- dos.writeInt(counter);
- dos.close();
- } catch (IOException ex) {
- Logger.getLogger(Jedinacek.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public int getCounter() {
- return counter;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement