From 08ce38dc1d4bc74f4deaac0cd86d7d1a6974ad87 Mon Sep 17 00:00:00 2001 From: wendal Date: Sun, 22 Sep 2013 11:31:40 +0800 Subject: [PATCH] =?UTF-8?q?add:=20Files=E7=B1=BB=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=8C=89=E8=A1=8C=E8=AF=BB=E5=8F=96=E7=9A=84API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/nutz/lang/Files.java | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/org/nutz/lang/Files.java b/src/org/nutz/lang/Files.java index 6c063b88e..da117f38e 100644 --- a/src/org/nutz/lang/Files.java +++ b/src/org/nutz/lang/Files.java @@ -2,6 +2,7 @@ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; +import java.io.BufferedReader; import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; @@ -18,6 +19,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import org.nutz.lang.util.Callback; import org.nutz.lang.util.ClassTools; import org.nutz.lang.util.Disks; @@ -989,4 +991,33 @@ else if (flag) public static boolean copyOnWrite(String path, Object obj) { return copyOnWrite(new File(path), obj); } + + public static List readLines(File f) { + List lines = new ArrayList(); + BufferedReader br = null; + try { + br = Streams.buffr(Streams.fileInr(f)); + while (br.ready()) + lines.add(br.readLine()); + } catch (IOException e) { + throw Lang.wrapThrow(e); + } finally { + Streams.safeClose(br); + } + return lines; + } + + public static void readLine(File f, Callback callback) { + BufferedReader br = null; + try { + br = Streams.buffr(Streams.fileInr(f)); + while (br.ready()) + callback.invoke(br.readLine()); + } catch (ExitLoop e) { + } catch (IOException e) { + throw Lang.wrapThrow(e); + } finally { + Streams.safeClose(br); + } + } }