Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java scala InputStreamReader未读取整个数据(文件)_Java_Scala_Rest_Http - Fatal编程技术网

Java scala InputStreamReader未读取整个数据(文件)

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

我试图通过scala rest调用访问tally服务器,并将输出保存在文件中

当我做同样的卷曲时,我得到大约412K行的输出 但当我通过scala访问时,我只收到411K条线路(大约有500条线路丢失)

这是因为缓冲区大小问题吗

下面是我的代码

    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
}