程序在执行以下函数时抛出异常:
testDownloadFunc: function() {
console.log("testDownload");
var remoteFile = "http://192.168.55.177/MvcApplication6/Download/getFile";
var localFileName = "Test01.properties";
function fail(error) {
console.log(error.code);
}
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile(localFileName, {create: true, exclusive: false}, function(fileEntry) {
var localPath = fileEntry.fullPath;
if (device.platform === "Android" && localPath.indexOf("file://") === 0) {
localPath = localPath.substring(7);
}
var ft = new FileTransfer();
ft.download(remoteFile,
localPath, function(entry) {
console.log("download complete: " + entry.fullPath);
}, fail);
}, fail);
}, fail);
}
抛出以下异常:02-01 16:01:16.920: E /文件传输(23147): {“target”:“/ storage / sdcard0 / Test01.properties”,“source”:“http://192.168.55.177/MvcApplication6/Download/getFile”,“http_status”:200,“code”:3} 02- 01 16:01:16.920:E / FileTransfer(23147):java.net.SocketException: recvfrom失败:ECONNRESET(由对等方重置连接)02-01 16:01:16.920:E / FileTransfer(23147):at libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java:552)02-01 16:01:16.920:E / FileTransfer(23147):at libcore.io.IoBridge.recvfrom(IoBridge.java:516)02-01 16:01:16.920: E / FileTransfer(23147):at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)02-01 16:01:16.920:E / FileTransfer(23147):at java.net.PlainSocketImpl.access $ 000(PlainSocketImpl.java:46)02-01 16:01:16.920:E / FileTransfer(23147):at java.net.PlainSocketImpl $ PlainSocketInputStream.read(PlainSocketImpl.java:240) 02-01 16:01:16.920:E / FileTransfer(23147):at java.io.BufferedInputStream.read(BufferedInputStream.java:304)02-01 16:01:16.920:E / FileTransfer(23147):at libcore.net.http.ChunkedInputStream.read(ChunkedInputStream.java:52) 02-01 16:01:16.920:E / FileTransfer(23147):at java.io.InputStream.read(InputStream.java:163)02-01 16:01:16.920: E / FileTransfer(23147):at org.apache.cordova.FileTransfer.download(FileTransfer.java:507)02-01 16:01:16.920:E / FileTransfer(23147):at org.apache.cordova.FileTransfer.execute(FileTransfer.java:88)02-01 16:01:16.920:E / FileTransfer(23147):at org.apache.cordova.api.PluginManager $ 1.run(PluginManager.java:231) 02-01 16:01:16.920:E / FileTransfer(23147):at java.lang.Thread.run(Thread.java:856)02-01 16:01:16.920: E / FileTransfer(23147):引起:libcore.io.ErrnoException:recvfrom 失败:ECONNRESET(由对等方重置连接)02-01 16:01:16.920: E / FileTransfer(23147):at libcore.io.Posix.recvfromBytes(Native 方法)02-01 16:01:16.920:E / FileTransfer(23147):at libcore.io.Posix.recvfrom(Posix.java:131)02-01 16:01:16.920: E / FileTransfer(23147):at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164)02-01 16:01:16.920:E / FileTransfer(23147):at libcore.io.IoBridge.recvfrom(IoBridge.java:513)02-01 16:01:16.920: E / FileTransfer(23147):... 10多个
问题的根本原因是什么以及如何解决? 我使用的是PhoneGap 2.1和Android 4.1.2。
答案 0 :(得分:1)
我不确定,但这个问题出现在java IO核心的某个地方,同时读取太多行的文本,我通过减少我的JSON代码的行数来解决这个问题。到10行。
我想出了这个解决方案,因为我使用java做了同样的工作,遇到同样的问题,当它到达BufferedReader.readLine()
方法时。
此外,以另一种方式读取文件可能会有所帮助,例如使用byteBuffer或其他方式读取文件。但在你的情况下(电话差距),我没有IDEA:D