import java.io.*; import java.util.Date; import java.net.*; import java.io.IOException; import java.util.StringTokenizer; class Failnet { static String ni; static String pa; public Failnet(String unimi, String uparool){ ni=unimi; pa=uparool; } public static void main(String argumendid[])throws IOException{ ServerSocket ss=new ServerSocket(5656); while(true){ Socket sc=ss.accept(); PrintWriter valja=new PrintWriter(sc.getOutputStream(), true); int rarv=ridadearv("fail.txt"); System.out.println("Valja loodud"); PrintWriter faili=new PrintWriter( new FileWriter("fail.txt",true),true ); rarv=rarv+1; valja.println("Sinu jarjekorra number on "+rarv ); System.out.println("Valja trykitud"); BufferedReader sisse=new BufferedReader( new InputStreamReader(sc.getInputStream()) ); ni=sisse.readLine(); if(kasutaja(ni)==false) { System.out.println("Uus kasutaja"); valja.println("Kirjuta sa oled uus kasutaja" ); pa=sisse.readLine(); faili.println(ni+ " "+pa);} else{ System.out.println("Vana kasutaja"); valja.println("Sisesta oma parool"); pa=sisse.readLine(); if(kasutaja(pa)==false)valja.println("Parool ei ole oige"); else{valja.println("Nuud sa saad kellaaja teada:"+new Date().getTime()); } } faili.close(); 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; } static boolean kasutaja(String kasutajanimi){ boolean onolemas=false; String rida=""; try{ BufferedReader sisse=new BufferedReader( new FileReader("fail.txt") ); while((rida=sisse.readLine())!=null){ StringTokenizer st=new StringTokenizer(rida, " "); while(st.hasMoreTokens()){ String sona=st.nextToken(); if(sona.equals(kasutajanimi)){ onolemas=true; } }} } catch (Exception probleem){ onolemas=false; }; return onolemas; } }