1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import java.net.*;
- import java.io.*;
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author LH
- */
- class Filter{
- public static void main(String[] args) throws Exception{
- InputStreamReader isr;
- BufferedReader userInput;
- String textInput;
- String searchword;
-
- /** Benutzereingabe */
- isr = new InputStreamReader(System.in);
- userInput = new BufferedReader(isr);
- System.out.println("Geben Sie einen URL ein: ");
- textInput = userInput.readLine();
- System.out.println("Geben Sie den Suchtext ein");
- searchword = userInput.readLine();
-
- /**
- * 1. Neuen Url anlegen
- * 2. Url als Stream öffnen und nach FilterInputStream casten
- * 3. FilterInputStream -> BufferedReader
- */
- URL u = new URL(textInput);
- FilterInputStream ins = (FilterInputStream) u.openStream();
- InputStreamReader ir = new InputStreamReader(ins);
- BufferedReader site= new BufferedReader(ir);
-
- /** Lesen der ersten Zeile im Fall von null */
- String line = site.readLine();
-
- /** Restliche Zeilen einlesen und bei enthaltenem Suchstring ausgeben */
- while(line != null){
- System.out.print(line.contains(searchword)?line+"\n":"");
- line=site.readLine();
- }
- }
-
- }
|