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)

1  
lib 1003724
2  
3  
import org.apache.commons.io.input.ReversedLinesFileReader;
4  
5  
static LS lastNLines(File f, int n) ctex {
6  
  if (f == null) ret emptyList();
7  
  
8  
  try {
9  
    ReversedLinesFileReader r = new(f);
10  
    try {
11  
      new LS l;
12  
      while(l(l) < n) {
13  
        S s = r.readLine();
14  
        if (s == null) break;
15  
        l.add(s);
16  
      }
17  
      ret reversedList(l);
18  
    } finally {
19  
      r.close();
20  
    }
21  
  } catch (FileNotFoundException e) {
22  
    ret emptyList();
23  
  }
24  
}
25  
26  
static L<S> lastNLines(int n, File f) {
27  
  ret lastNLines(f, n);
28  
}

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: 614 / 617
Version history: 4 change(s)
Referenced in: [show references]