import java.io.*; import java.net.*; class Failnetti1 { static String n; static String p; public Failnetti1(String un, String up){ n=un; p=up; } public static void main(String argumendid[])throws IOException{ ServerSocket ss=new ServerSocket(2345); while(true){ Socket sc=ss.accept(); BufferedReader sisse=new BufferedReader( new InputStreamReader(sc.getInputStream()) ); PrintWriter valja=new PrintWriter(sc.getOutputStream()); int nr=Integer.parseInt(sisse.readLine()); int rarv=ridadearv("paev"+nr+".txt"); if (rarv<=19){ PrintWriter faili=new PrintWriter( new FileWriter("paev"+nr+".txt",true),true ); n=sisse.readLine(); p=sisse.readLine(); faili.println(n+ " | "+p); faili.close(); valja.println("Koht olemas"); } else{ valja.println("Kohad on täis!!!!!!"); } valja.close(); }; } static int ridadearv(String failinimi){ int miturida=0; try{ BufferedReader sisse=new BufferedReader( new FileReader(failinimi) ); while(sisse.readLine()!=null)miturida++; } catch (Exception probleem){ miturida=0; }; return miturida; } }