Я реализовал загрузку файлов. Он загружает и сохраняет его в памяти.Как зашифровать папки и загрузить
Теперь моя проблема в том, что если есть папка и подпапка, мне нужно ZIP-папку и загрузить zip-файл и сохранить его в памяти. Я пробовал много, но я не нашел решения. Может ли кто-нибудь помочь мне получить решение?
Здесь мой скачать единый код файл ...
@Override
protected String doInBackground(String... sUrl) {
InputStream input = null;
OutputStream output = null;
ZipOutputStream zos = null;
HttpURLConnection connection = null;
try {
URL url = new URL(sUrl[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
return "Server returned HTTP "
+ connection.getResponseCode() + " "
+ connection.getResponseMessage();
}
String fileName = tvtitle.getText().toString();
String fileExtension = tvtype.getText().toString();
File imageDirectory = new File(Path);
imageDirectory.mkdirs();
int fileLength = connection.getContentLength();
String _path = Path;
input = connection.getInputStream();
File outputFile = new File(_path, fileName + fileExtension);
output = new FileOutputStream(outputFile);
// zos = new ZipOutputStream(output);
byte data[] = new byte[4096];
long total = 0;
int count;
while ((count = input.read(data)) != -1) {
if (isCancelled()) {
input.close();
return null;
}
total += count;
if (fileLength > 0) // only if total length is known
publishProgress((int) (total * 100/fileLength));
output.write(data, 0, count);
}
} catch (Exception e) {
return e.toString();
} finally {
try {
if (output != null)
output.close();
if (input != null)
input.close();
} catch (IOException ignored) {
}
if (connection != null)
connection.disconnect();
}
return null;
}
На самом деле вы должны написать код для zipping на сервере. Android просто загрузит все, что предоставляется. – Paritosh
есть идентификатор метода ZipOutputStream, но я dnt knw, как его использовать – Piku