我一直在尝试通过网络服务下载一些文件并完美下载,但现在我正在尝试添加一个功能,如果文件没有完全下载,应用程序应该只下载剩余的字节数组并附加到现有的,使用
connection = (HttpConnection) cf.getConnection(_url).getConnection();
int alreadyDownloaded = 0;
if(connection.getResponseCode() == HttpConnection.HTTP_OK) {
inputStream = new DataInputStream(connection.openInputStream());
final int len = (int) connection.getLength();
if (len > 0) {
String filename = _url.substring(_url.lastIndexOf('/') + 1);
FileConnection outputFile = (FileConnection) Connector.open(path + filename, Connector.READ_WRITE, true);
if (!outputFile.exists()) {
outputFile.create();
} else {
alreadyDownloaded = (int) outputFile.fileSize();
connection.setRequestProperty("Range", "bytes=" + alreadyDownloaded + "-");
}
在这条线上
connection.setRequestProperty("Range", "bytes=" + alreadyDownloaded + "-");
我得到一个例外,说
流未处于设置状态
我怎样才能摆脱这个错误?