在Tmp文件中没有数据创建

时间:2019-05-06 16:00:20

标签: scala java-io

在下面的测试中,我需要创建一个临时文件并添加一些内容,调用main方法,然后查看是否生成了正确的输出。

我可以看到在“ / tmp”中创建的文件,但它始终为空。就像BufferedWriter不在写它。我在做什么错了?

library(lubridate)
library(rvest)

oldurl <- "https://waterdata.usgs.gov/ca/nwis/uv/?site_no=11401920&PARAmeter_cd=00065,00060"

flow = html_text(html_node(read_html(oldurl),".stationContainer:nth-child(5)"))  #Selector ID'd by https://selectorgadget.com/
stage = html_text(html_node(read_html(oldurl),".stationContainer:nth-child(6)")) #Selector ID'd by https://selectorgadget.com/


flow <- gsub("(T).*","\\1", flow)
flow <- gsub("Most recent instantaneous value:","", flow)
flow <- gsub("\n","", flow)
flow <- gsub("Discharge, cubic feet per second","cfs", flow)
flow <- gsub("(?<=[\\s])\\s*|^\\s+|\\s+$", "", flow, perl=TRUE)
flow <- strsplit(flow, " ")
flow <- unlist(flow)
unit <- flow[1]
value <- flow[2]
date <- paste0(flow[3]," ", flow[4], " ", flow[5])
flow <- data.frame(value, unit, date) %>% mutate(value = 
        as.character(value), value = as.integer(value), date = mdy_hm(date))
as_tibble(flow)
#<int> <fct>    <dttm>             
#363    cfs      2019-05-06 07:30:00

stage <-gsub("(T).*","\\1", stage)
stage <-gsub("Most recent instantaneous value:","", stage)
stage <-gsub("\n","", stage)
stage <-gsub("Gage height, feet ","ft", stage)
stage <- gsub("(?<=[\\s])\\s*|^\\s+|\\s+$", "", stage, perl=TRUE)
stage <- strsplit(stage, " ")
stage <- unlist(stage)
unit <- stage[1]
value <- stage[2]
date <- paste0(stage[3]," ", stage[4], " ", stage[5])
stage <- data.frame(value, unit, date) %>% mutate(value = 
        as.character(value), value = as.double(value), date = 
        mdy_hm(date))
as_tibble(stage)
# <dbl>    <fct>   <dttm>             
# 6.32      ft     2019-05-06 07:30:00

## how to get the same, flow and stage, from their new page?
newurl <- "https://waterdata.usgs.gov/monitoring-location/11401920/" 

0 个答案:

没有答案