Groovy逐行读取文件,eachLine方法使用BufferedReader

时间:2015-11-30 15:45:13

标签: groovy

我写了一个groovy脚本来逐行读取一个巨大的文件。

我目前正在使用样板代码,如下所示

File hugeFile = new File(filePath)
if (hugeFile.exists()) {
    hugeFile.eachLine {line ->
        //some process
    }
}

我的问题是如何判断“eachLine”是否使用BufferedReader来提高内存效率?

1 个答案:

答案 0 :(得分:6)

试一下它是否可以处理大文件。

然后查看source at github

library(boot)
x <- structure(list(Customer = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                 1L, 1L), Application = c(1L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 
                                                          1L, 1L)), .Names = c("Customer", "Application"), class = "data.frame", row.names = c(NA, 
                                                                                                                                               -11L))
f2 <- function(x, index){sum(x[index, "Application"])/sum(x[index, "Customer"])}
bootapp1 <- boot(data = x, statistic = f2, R = 1000)
> bootapp1

ORDINARY NONPARAMETRIC BOOTSTRAP


Call:
  boot(data = x, statistic = f2, R = 1000)


Bootstrap Statistics :
  original       bias    std. error
t1* 0.5454545 0.0005454545     0.14995