Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.util.Arrays;
- class fyle implements Iterable<String>{
- private BufferedReader reader;
- public fyle(String path) throws Exception{
- reader = new BufferedReader(new FileReader(path));}
- public void close() throws IOException{reader.close();}
- public Iterator<String> iterator() {return new FileIterator();}
- private class FileIterator implements Iterator<String>{
- private String currentLine;
- public boolean hasNext() {
- try{currentLine = reader.readLine();
- }catch(Exception E){
- currentLine=null;
- E.printStackTrace();}
- return currentLine != null;}
- public String next() {
- return currentLine;}
- public void remove() {}
- }}
- public class fileClass {
- public static int n, position=0;
- public fileClass(String path) throws Exception{
- fyle f= new fyle(path);
- for(String j:f){n+=1;}
- int[] k=new int[5];
- for (int i=0; i<5; i++){ k[i] = 1+((int)(Math.random() * (n)));}
- Arrays.sort(k);
- fyle f2= new fyle(path);
- for(String j2:f2){
- position++;
- for(int i=0;i<5;i++){
- if(position== k[i]){
- System.out.println("Random Line Number:" + k[i] + " " + j2);
- }}}}
- public static void main(String[] args) throws Exception{
- try{
- fileClass _new=new fileClass(args[0]);
- }catch(Exception e){
- System.out.println("Error :p");
- }}}
Advertisement
Add Comment
Please, Sign In to add comment