Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Libraries for sysadmins? Date: Fri, 4 Mar 2016 18:06:40 +0100 Lines: 51 Message-ID: References: <2cec6af2-9636-4a2a-8849-b01286c0814c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net kDGr85eoStMJMCTKmvvA7gIW+FlzfbguCbh7PkIXly8s7T66Q= Cancel-Lock: sha1:ikqPRjEn/LAM0oqxCamHFrM3pwg= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:33922 I would look into using JRuby, maybe also look into Groovy (not sure how much alive the latter is these days). On 04.03.2016 16:13, Stefan Ram wrote: > Elena writes: >> processing text files line by line > > Writing lines to a text file: > > new java.io.FileWriter( "c:\\example.txt" ). > append( "alpha\n" ).close(); In (J)Ruby: File.open("example.txt", "a") {|io| io.puts "alpha"} > Reading a text file line by line (not tested): > > final java.util.Scanner scanner > = new java.util.Scanner( new java.io.File( "file.txt" )); > while( scanner.hasNextLine() ) > { final java.lang.String line = scanner.nextLine(); In (J)Ruby: File.foreach "file.txt" do |line| # whatever end >> filtering collections > > (not tested): > > java.util.Arrays.asList( 1, 2, 3 ).stream(). > filter( x -> "x >= 2 ) Again, in (J)Ruby: [1,2,3].select {|x| x >= 2} (Not exactly the same, but can easily be made to if need be.) Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/