簡體   English   中英

從URL以編程方式在Android中下載Mp3

[英]Downloading Mp3 in Android Programmatically from a URL

我想從Web服務器上下載帶有聲音URL的Mp3聲音。 我不知道什么是最好的方法! 我也研究了這些問題。 請指引我正確的方向。

在Android上以編程方式下載文件

在Android中以編程方式從網上下載文件的最佳方法是什么?

試試這個代碼,讓我知道

File output = new File(Environment.getExternalStorageDirectory(),
    fileName);
if (output.exists()) {
  output.delete();
}

InputStream stream = null;
FileOutputStream fos = null;
try {

  URL url = new URL(urlPath);
  stream = url.openConnection().getInputStream();
  InputStreamReader reader = new InputStreamReader(stream);
  fos = new FileOutputStream(output.getPath());
  int next = -1;
  while ((next = reader.read()) != -1) {
    fos.write(next);
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM