我想将mp3文件放入SD卡。在 java.io.FileNotFoundException:144128111104895_20150824112314028.mp3的SD卡中保存文件时出错:在此行打开失败:EROFS(只读文件系统) fileOutput = new FileOutputStream(file ); 和引起:android.system.ErrnoException:open failed:EROFS(只读文件系统)在此行 fileOutput = new FileOutputStream(file); 。当我浏览文件链接时,文件大小为0字节。那么如何删除0字节大小的文件。错误发生在
这是我的下载mp3方法
void download_Mp3File(String fileUrl)
{
URL mp3_url = null;
InputStream inputStream = null;
int bufferLength = 0;
int downloadedSize = 0;
byte[] buffer = new byte[1024];
if( buffer != null)
{
try
{
mp3_url = new URL(fileUrl);
}
catch (MalformedURLException mfe)
{
mfe.printStackTrace();
}
HttpURLConnection urlConnection = null;
try
{
urlConnection = (HttpURLConnection) mp3_url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
File file = new File(newFolder, System.currentTimeMillis()+imageName);
file.deleteOnExit();
FileOutputStream fileOutput = null;
try
{
fileOutput = new FileOutputStream(file);
inputStream = urlConnection.getInputStream();
int totalSize = urlConnection.getContentLength();
Log.e("totalSize ", " = " + totalSize);
} catch (FileNotFoundException fne) {
fne.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
while ((bufferLength = inputStream.read(buffer)) > 0)
{
fileOutput.write(buffer, 0, bufferLength);
//bm.compress(Bitmap.CompressFormat.PNG, 100, fileOutput1);
downloadedSize += bufferLength;
// Log.e("downloadedSize", " = " + downloadedSize);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// close the output stream when done
try {
fileOutput.close();
Log.e("MP3 = ", "DownLoad complete");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这是我的LogCat信息
09-03 17:21:51.042 20396-20458/? E/mp3_Pattern﹕ str_ImageUrl = http://103.24.4.60/CLASSNK1/MobileService.svc/DownloadFile/FileName/95_20150824112314028.mp3
09-03 17:21:51.049 20396-20458/? W/System.err﹕ java.io.FileNotFoundException: 144128111104895_20150824112314028.mp3: open failed: EROFS (Read-only file system)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:456)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at java.io.FileOutputStream.<init>(FileOutputStream.java:72)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at com.example.tazeen.classnkk.Service_AllPost.download_Mp3File(Service_AllPost.java:444)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at com.example.tazeen.classnkk.Service_AllPost.getAllImagePath_List(Service_AllPost.java:256)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at com.example.tazeen.classnkk.Service_AllPost$MyAsyncTask.doInBackground(Service_AllPost.java:114)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at com.example.tazeen.classnkk.Service_AllPost$MyAsyncTask.doInBackground(Service_AllPost.java:105)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:292)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at libcore.io.Posix.open(Native Method)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:442)
09-03 17:21:51.049 20396-20458/? W/System.err﹕ ... 12 more
09-03 17:21:51.050 20396-20458/? W/System.err﹕ java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.InputStream.read(byte[])' on a null object reference
09-03 17:21:51.050 20396-20458/? W/System.err﹕ at com.example.tazeen.classnkk.Service_AllPost.download_Mp3File(Service_AllPost.java:457)
09-03 17:21:51.050 20396-20458/? W/System.err﹕ at com.example.tazeen.classnkk.Service_AllPost.getAllImagePath_List(Service_AllPost.java:256)
09-03 17:21:51.050 20396-20458/? W/System.err﹕ at com.example.tazeen.classnkk.Service_AllPost$MyAsyncTask.doInBackground(Service_AllPost.java:114)
09-03 17:21:51.050 20396-20458/? W/System.err﹕ at com.example.tazeen.classnkk.Service_AllPost$MyAsyncTask.doInBackground(Service_AllPost.java:105)
09-03 17:21:51.050 20396-20458/? W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:292)
09-03 17:21:51.050 20396-20458/? W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
09-03 17:21:51.050 20396-20458/? W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
09-03 17:21:51.050 20396-20458/? W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
09-03 17:21:51.050 20396-20458/? W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
09-03 17:21:51.050 20396-20458/? W/System.err﹕ at java.lang.Thread.run(Thread.java:818)