Here you can find the source of readFileOneLine(String filename, String keyInLine)
public static String readFileOneLine(String filename, String keyInLine) throws Exception
//package com.java2s; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; public class Main { public static String readFileOneLine(String filename, String keyInLine) throws Exception { File f = new File(filename); if (!f.exists()) return null; FileInputStream fis = null; InputStreamReader fsr = null; BufferedReader reader1 = null; String line;// www . j a v a 2 s . c o m try { fis = new FileInputStream(filename); fsr = new InputStreamReader(fis, "UTF-8"); reader1 = new BufferedReader(fsr); while ((line = reader1.readLine()) != null) { if (line.indexOf(keyInLine) != -1) { break; } } } finally { try { if (reader1 != null) reader1.close(); } catch (Exception e) { e.printStackTrace(); } try { if (fsr != null) fsr.close(); } catch (Exception e) { e.printStackTrace(); } try { if (fis != null) fis.close(); } catch (Exception e) { e.printStackTrace(); } } return line; } }