Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

28
LINES

< > BotCompany Repo | #1004746 // lastNLines - read last n lines of file

JavaX fragment (include)

lib 1003724

import org.apache.commons.io.input.ReversedLinesFileReader;

static LS lastNLines(File f, int n) ctex {
  if (f == null) ret emptyList();
  
  try {
    ReversedLinesFileReader r = new(f);
    try {
      new LS l;
      while(l(l) < n) {
        S s = r.readLine();
        if (s == null) break;
        l.add(s);
      }
      ret reversedList(l);
    } finally {
      r.close();
    }
  } catch (FileNotFoundException e) {
    ret emptyList();
  }
}

static L<S> lastNLines(int n, File f) {
  ret lastNLines(f, n);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004746
Snippet name: lastNLines - read last n lines of file
Eternal ID of this version: #1004746/5
Text MD5: c88db94340cad58f9a8acf3079db7533
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-01-15 18:52:40
Source code size: 560 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 610 / 611
Version history: 4 change(s)
Referenced in: [show references]