import java.io.*; public class FailisLoendaja implements Loendaja{ private String failinimi; public FailisLoendaja(String fnimi){ failinimi=fnimi; nulli(); } protected void kirjutaFaili(int arv){ try{ PrintWriter faili=new PrintWriter(new FileWriter(failinimi)); faili.println(arv); faili.close(); } catch(IOException ex){ex.printStackTrace();} } protected int loeFailist(){ try{ BufferedReader failist=new BufferedReader( new FileReader(failinimi)); int arv=Integer.parseInt(failist.readLine()); failist.close(); return arv; } catch(IOException ex){ex.printStackTrace();} return -1; } public void nulli(){kirjutaFaili(0);} public void lisa(){kirjutaFaili(loeFailist()+1);} public int kysi(){return loeFailist();} }