How to download a file from the server

I have a question with the overall implementation of the design. Hope someone more qualified than me helps me.

I want to make an application based on android client and java server. Local Wi-Fi, 3G.

Basically, the client should connect to the server and request the download of the file using the code.

How can i do this?

Things I know:

  • I have to create a background thread in the client to create the file on the SD card and update the progress bar using Handler to communicate with the user interface thread.

  • The server must be multithreaded and non-blocking.

  • A file is a binary file such as mp3 audio. Therefore, the server should:

    • Send file information: name and total length.
    • Open the file, read and send the bytes until it reaches the end.

  • :

    • .
    • . .
    • , .

C ( ), -, java.

:

  • , , mp3 ?

  • ? , , , ?

!

+3
1

, , mp3 ?

Java, URL.openStream();

http://download.oracle.com/javase/tutorial/networking/urls/readingURL.html

System.out. .

FileOutputStream fos = new FileOutputStreamm(new File("path_to_file.mp3");
int byte;

while ((byte= in.readLine()) != -1)
    fos.write(byte);

? , . http-, (Tomcat oder Apache HTTPD). HTTP.

Java-, Servlet WAR -File:

http://docstore.mik.ua/orelly/java-ent/servlet/

+5

Source: https://habr.com/ru/post/1778812/


All Articles