程序在执行以下函数时抛出异常:
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/FileTransfer(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 failed: ECONNRESET(连接重置通过对等)02-01 16:01:16.920:E/FileTransfer(23147):在 libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java:552)02-01 16:01:16.920:E/FileTransfer(23147):在 libcore.io.IoBridge.recvfrom(IoBridge.java:516) 02-01 16:01:16.920: E/FileTransfer(23147): 在 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): 在 java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240) 02-01 16:01:16.920: E/FileTransfer(23147): 在 java.io.BufferedInputStream .read(BufferedInputStream.java:304) 02-01 16:01:16.920: E/FileTransfer(23147): 在 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): 在 org.apache.cordova.api.PluginManager$1.run(PluginManager.java:231) 02-01 16:01:16.920: E/FileTransfer(23147):在 java.lang.Thread.run(Thread.java:856) 02-01 16:01:16.920: E/FileTransfer(23147): Caused by: libcore.io.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer) 02-01 16:01:16.920: E/FileTransfer(23147): 在 libcore.io.Posix.recvfromBytes(Native Method) 02-01 16:01:16.920: E/FileTransfer(23147): 在 libcore.io.Posix .recvfrom(Posix.java:131) 02-01 16:01:16.920: E/FileTransfer(23147): 在 libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164) 02-01 16:01:16.920: E /FileTransfer(23147): 在 libcore.io.IoBridge.recvfrom(IoBridge.java:513) 02-01 16:01:16.920: E/FileTransfer(23147): ... 还有 10 个E/FileTransfer(23147): 在 libcore.io.Posix.recvfromBytes(Native Method) 02-01 16:01:16.920: E/FileTransfer(23147): 在 libcore.io.Posix.recvfrom(Posix.java:131) 02-01 16:01:16.920: E/FileTransfer(23147): 在 libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164) 02-01 16:01:16.920: E/FileTransfer(23147): 在 libcore。 io.IoBridge.recvfrom(IoBridge.java:513) 02-01 16:01:16.920: E/FileTransfer(23147): ... 10 更多E/FileTransfer(23147): 在 libcore.io.Posix.recvfromBytes(Native Method) 02-01 16:01:16.920: E/FileTransfer(23147): 在 libcore.io.Posix.recvfrom(Posix.java:131) 02-01 16:01:16.920: E/FileTransfer(23147): 在 libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164) 02-01 16:01:16.920: E/FileTransfer(23147): 在 libcore。 io.IoBridge.recvfrom(IoBridge.java:513) 02-01 16:01:16.920: E/FileTransfer(23147): ... 10 更多
问题的根本原因是什么以及如何解决?我使用 PhoneGap 2.1 和 Android 4.1.2。