Java: Unterschied zwischen den Versionen

Aus Info-Theke
Zur Navigation springen Zur Suche springen
Zeile 7: Zeile 7:
while( (line = reader.readLine()) != null)
while( (line = reader.readLine()) != null)
   doIt(line);
   doIt(line);
</pre>
== Reguläre Ausdrücke ==
<pre>Pattern rexpr = Pattern.compile("Name: (\\w+)");
Matcher matcher;
while( (line = reader.readLine()) != null){
  if ( (matcher = rexpr.matcher(line)).find()){
      name = matcher.group(1);
  }
}
</pre>
</pre>

Version vom 19. April 2016, 13:40 Uhr


Resource aus Jar lesen

InputReader input = getClass().getResourceAsStream("appl.properties");
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line;
while( (line = reader.readLine()) != null)
   doIt(line);

Reguläre Ausdrücke

Pattern rexpr = Pattern.compile("Name: (\\w+)");
Matcher matcher;
while( (line = reader.readLine()) != null){
   if ( (matcher = rexpr.matcher(line)).find()){
      name = matcher.group(1);
   }
}