Android 如何从服务器下载文件找不到错误文件?
您能告诉我如何从服务器下载文件吗?我正在获取错误填充未找到错误Android 如何从服务器下载文件找不到错误文件?,android,Android,您能告诉我如何从服务器下载文件吗?我正在获取错误填充未找到错误 07-30 17:10:28.849: W/System.err(14900): java.io.FileNotFoundException: /testnaveen: open failed: EROFS (Read-only file system) 07-30 17:10:28.849: W/System.err(14900): at libcore.io.IoBridge.open(IoBridge.java:409)
07-30 17:10:28.849: W/System.err(14900): java.io.FileNotFoundException: /testnaveen: open failed: EROFS (Read-only file system)
07-30 17:10:28.849: W/System.err(14900): at libcore.io.IoBridge.open(IoBridge.java:409)
07-30 17:10:28.849: W/System.err(14900): at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
07-30 17:10:28.849: W/System.err(14900): at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
07-30 17:10:28.849: W/System.err(14900): at java.io.FileOutputStream.<init>(FileOutputStream.java:117)
07-30 17:10:28.849: W/System.err(14900): at com.mobilecem.atms.GlobalFunction.downloadFileFromServer(GlobalFunction.java:147)
我叫两个方向,但热相同的错误为什么
GlobalFunction.downloadFileFromServer("test", "http://www.example.com/inputParameters.js");
GlobalFunction.downloadFileFromServer( new File(Activity.this.getFilesDir(),"www").getAbsolutePath(), "url");
如果您使用的是Honeycom或更高版本,则需要使用来调用与网络相关的操作
使用下载管理器。 下载管理器的优点:
package com.example.testing;
import android.app.Activity;
import android.app.DownloadManager;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
public class FileDownloading extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startDownload("http://www.example.com/inputParameters.js","inputParameters.js");
}
public void startDownload(String url ,String fileName)
{
Log.d("Download Url", url);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setTitle("Your File Name");
request.setDescription(fileName+" is downloading..");
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
long downloadID = downloadManager.enqueue(request);
}
}
不要忘记在
manifest.xml中使用Internet和存储权限
确保您的文件不是只读的。已在清单中提供写入外部存储权限?已写入menifest文件。请从服务器下载文件,确保文件名正确,并将其上载到服务器上。如果您点击类似按钮,则会将其上载到服务器上,因为有文件。但文件名是什么?我提到任何东西,你必须重写它才能使用AsyncTask
package com.example.testing;
import android.app.Activity;
import android.app.DownloadManager;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
public class FileDownloading extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startDownload("http://www.example.com/inputParameters.js","inputParameters.js");
}
public void startDownload(String url ,String fileName)
{
Log.d("Download Url", url);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setTitle("Your File Name");
request.setDescription(fileName+" is downloading..");
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
long downloadID = downloadManager.enqueue(request);
}
}