MezData-LogoCreative Commons License Lösung 2007-So-FIS-A2

2.1 Struktogramm

2.2 Java-Quelltext

import java.io.*;

public class LogChecker{
  public static int test(){
    return anzahlLogs2("auth.log","Apr");    
  }
  
  public static int anzahlLogs2(String filename, String month)  { // nicht im Struktogramm darstellbar
    int anzahl=0;
    String zeile;
    try {
      BufferedReader ein = new BufferedReader(new FileReader(filename));
      while ((zeile = ein.readLine())!= null){ 
        if (zeile.substring(0,3).equals(month)) anzahl++;
      }
      ein.close();
    } catch (IOException e) {
       System.out.println("IOException: " + e);   
    }
    return anzahl;
  }
  
  public static int anzahlLogs(String filename, String month) throws IOException { 
    int anzahl=0;
    String zeile;
    BufferedReader ein = new BufferedReader(new FileReader(filename));
    while ((zeile = ein.readLine())!= null){ 
      if (zeile.substring(0,3).equals(month)) anzahl++;
    }
    ein.close();
    return anzahl;
  }
}
© Oliver Mezger 20.11.2008 MezData.de Den Kontakt herstellen...