Here you can find the source of read(File path, int i)
Parameter | Description |
---|---|
path | a parameter |
i | number of line |
private static String read(File path, int i)
//package com.java2s; import java.io.File; import java.io.FileNotFoundException; import java.util.NoSuchElementException; import java.util.Scanner; public class Main { /**//from w w w. java 2s. c o m * Read file in line i * * @param path * @param i * number of line * @return */ private static String read(File path, int i) { try { if (i == 1) { return new Scanner(path).nextLine(); } else { for (int j = 1; j < i; j++) { new Scanner(path).nextLine(); } return new Scanner(path).nextLine(); } } catch (FileNotFoundException e) { return null; } catch (NoSuchElementException n) { return null; } } public static String read(Scanner scan, int i) { try { if (i == 1) { i++; return scan.nextLine(); } else { for (int j = 1; j < i;) { scan.nextLine(); j++; } i++; return scan.nextLine(); } } catch (NoSuchElementException n) { return null; } } }