
package my3;
/**
 *
 * @author Viliam Krizan
 */

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;


public class KeyBoardData {
    private static int[] keyBoardData = new int[10];
    private static int counter = 0;
    
    public static void addData(int time){
        if(counter > 9){
            return;
        }
        
        keyBoardData[counter] = time;
        System.out.println(keyBoardData[counter]);
        
        
        if(counter == 9){
            counter++;
            saveDataToText();
            return;
        }
        counter++;
    }
    
    private static void saveDataToText() {
        
        File KeyboardData = new File("KeyboardData.txt");

        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter(KeyboardData));
            for (int i = 0; i < counter; i++) {
                //writer.append(keyBoardData[i] + System.lineSeparator());
                writer.write(keyBoardData[i] + System.lineSeparator());
                
            }
            writer.close();
        } catch (IOException ex) {
            System.out.println("cant write");
            ex.printStackTrace();
        }
    }
    
}
