从文件获取行开头
// Licensed under the Apache License, Version 2.0 (the "License"); import java.io.BufferedReader; /** from N o w J a v a . c o m**/ import java.io.File; import java.io.FileReader; import java.io.IOException; import org.apache.log4j.Logger; public class Main{ public static void main(String[] argv) throws Exception{ File file = new File("Main.java"); String value = "nowjava.com"; System.out.println(getLineBeginningWith(file,value)); } private static Logger logger = Logger.getLogger(FileReadHelper.class); public static String getLineBeginningWith(File file, String value) { try { BufferedReader reader = new BufferedReader(new FileReader(file)); String line; while ((line = reader.readLine()) != null) {// 来自 时 代 J a v a 公 众 号 - nowjava.com if (line.startsWith(value)) { break; } } reader.close(); return (line != null) ? line : ""; } catch (IOException e