Java scala InputStreamReader未读取整个数据(文件)
我试图通过scala rest调用访问tally服务器,并将输出保存在文件中 当我做同样的卷曲时,我得到大约412K行的输出 但当我通过scala访问时,我只收到411K条线路(大约有500条线路丢失) 这是因为缓冲区大小问题吗 下面是我的代码Java scala InputStreamReader未读取整个数据(文件),java,scala,rest,http,Java,Scala,Rest,Http,我试图通过scala rest调用访问tally服务器,并将输出保存在文件中 当我做同样的卷曲时,我得到大约412K行的输出 但当我通过scala访问时,我只收到411K条线路(大约有500条线路丢失) 这是因为缓冲区大小问题吗 下面是我的代码 httpConn.setRequestProperty("Content-Length", String.valueOf(b.length)) httpConn.setRequestProperty("Content-Type", "te
httpConn.setRequestProperty("Content-Length", String.valueOf(b.length))
httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8")
httpConn.setRequestMethod("POST")
httpConn.setDoOutput(true)
httpConn.setDoInput(true)
val out = httpConn.getOutputStream
out.write(b)
out.close()
val isr = new InputStreamReader(httpConn.getInputStream)
val in = new BufferedReader(isr)
var temp: String = null
temp= SaveFile(in) //pass stream to save into file
文件通过
def SaveFile(a: BufferedReader): String = {
val file = new File("OPinWorkspace.xml")
val bw = new BufferedWriter(new FileWriter(file))
Iterator
.continually (a.read)
.takeWhile (-1 !=)
.foreach (bw.write)
return foo
}
完成后,您需要创建您的流
close
首先刷新流
try {
// ...
} finally {
a.close
if(bw != null) bw.close // close and flush
}