java.io.FileNotFoundException: xxx: open failed: EROFS (Read-only file system)

12-21 17:21:13.672: W/System.err(1583): java.io.FileNotFoundException: /downloadedMusic.mp3: open failed: EROFS (Read-only file system) 
12-21 17:21:13.672: W/System.err(1583): at libcore.io.IoBridge.open(IoBridge.java:416) 
12-21 17:21:13.672: W/System.err(1583): at java.io.FileOutputStream.<init>(FileOutputStream.java:88) 
12-21 17:21:13.672: W/System.err(1583): at java.io.FileOutputStream.<init>(FileOutputStream.java:73) 
12-21 17:21:13.672: W/System.err(1583): at crifan.com.crifanLib.downlodFile(crifanLib.java:197) 
12-21 17:21:13.672: W/System.err(1583): at crifan.com.crifanLibSongtaste.stDownloadFromUrl(crifanLibSongtaste.java:204) 
12-21 17:21:13.672: W/System.err(1583): at crifan.com.downloadsongtastemusic.MainActivity.preformDownload(MainActivity.java:74) 
12-21 17:21:13.672: W/System.err(1583): at java.lang.reflect.Method.invokeNative(Native Method) 
12-21 17:21:13.672: W/System.err(1583): at java.lang.reflect.Method.invoke(Method.java:511) 
12-21 17:21:13.672: W/System.err(1583): at android.view.View$1.onClick(View.java:3586)
12-21 17:21:13.672: W/System.err(1583): at android.view.View.performClick(View.java:4084) 
12-21 17:21:13.672: W/System.err(1583): at android.view.View$PerformClick.run(View.java:16966) 
12-21 17:21:13.672: W/System.err(1583): at android.os.Handler.handleCallback(Handler.java:615) 
12-21 17:21:13.672: W/System.err(1583): at android.os.Handler.dispatchMessage(Handler.java:92) 
12-21 17:21:13.672: W/System.err(1583): at android.os.Looper.loop(Looper.java:137) 
12-21 17:21:13.672: W/System.err(1583): at android.app.ActivityThread.main(ActivityThread.java:4745) 
12-21 17:21:13.672: W/System.err(1583): at java.lang.reflect.Method.invokeNative(Native Method) 
12-21 17:21:13.672: W/System.err(1583): at java.lang.reflect.Method.invoke(Method.java:511) 
12-21 17:21:13.672: W/System.err(1583): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
12-21 17:21:13.672: W/System.err(1583): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
12-21 17:21:13.672: W/System.err(1583): at dalvik.system.NativeStart.main(Native Method) 
12-21 17:21:13.672: W/System.err(1583): Caused by: libcore.io.ErrnoException: open failed: EROFS (Read-only file system) 
12-21 17:21:13.672: W/System.err(1583): at libcore.io.Posix.open(Native Method) 
12-21 17:21:13.689: W/System.err(1583): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) 
12-21 17:21:13.689: W/System.err(1583): at libcore.io.IoBridge.open(IoBridge.java:400) 
12-21 17:21:13.689: W/System.err(1583): … 19 more

很明显,是没有权限去访问对应的位置:

/downloadedMusic.mp3

所以,接着就是去,想办法,如何将下载的东西,存储到Android中的,某个位置,程序有权限访问的位置。

去AndroidManifest.xml中添加了:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

然后继续添加代码。

结果代码:

File extDir = Environment.getExternalStorageDirectory();
String filename = "downloadedMusic.mp3";
File fullFilename =new File(extDir.getAbsolutePath() + extDir.pathSeparatorChar + filename);
 
try {
    fullFilename.createNewFile();
    fullFilename.setWritable(Boolean.TRUE);
    songtaste.stDownloadFromUrl(strSongUrl, fullFilename);
     
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

就出错了:

12-21 17:45:48.298: W/System.err(1547): java.io.IOException: open failed: EROFS (Read-only file system)

12-21 17:45:48.298: W/System.err(1547):     at java.io.File.createNewFile(File.java:940)

12-21 17:45:48.298: W/System.err(1547):     at crifan.com.downloadsongtastemusic.MainActivity.preformDownload(MainActivity.java:83)

12-21 17:45:48.298: W/System.err(1547):     at java.lang.reflect.Method.invokeNative(Native Method)

12-21 17:45:48.298: W/System.err(1547):     at java.lang.reflect.Method.invoke(Method.java:511)

12-21 17:45:48.298: W/System.err(1547):     at android.view.View$1.onClick(View.java:3586)

12-21 17:45:48.298: W/System.err(1547):     at android.view.View.performClick(View.java:4084)

12-21 17:45:48.298: W/System.err(1547):     at android.view.View$PerformClick.run(View.java:16966)

12-21 17:45:48.298: W/System.err(1547):     at android.os.Handler.handleCallback(Handler.java:615)

12-21 17:45:48.298: W/System.err(1547):     at android.os.Handler.dispatchMessage(Handler.java:92)

12-21 17:45:48.298: W/System.err(1547):     at android.os.Looper.loop(Looper.java:137)

12-21 17:45:48.298: W/System.err(1547):     at android.app.ActivityThread.main(ActivityThread.java:4745)

12-21 17:45:48.298: W/System.err(1547):     at java.lang.reflect.Method.invokeNative(Native Method)

12-21 17:45:48.298: W/System.err(1547):     at java.lang.reflect.Method.invoke(Method.java:511)

12-21 17:45:48.298: W/System.err(1547):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

12-21 17:45:48.298: W/System.err(1547):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

12-21 17:45:48.298: W/System.err(1547):     at dalvik.system.NativeStart.main(Native Method)

12-21 17:45:48.298: W/System.err(1547): Caused by: libcore.io.ErrnoException: open failed: EROFS (Read-only file system)

12-21 17:45:48.309: W/System.err(1547):     at libcore.io.Posix.open(Native Method)

12-21 17:45:48.309: W/System.err(1547):     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)

12-21 17:45:48.309: W/System.err(1547):     at java.io.File.createNewFile(File.java:933)

12-21 17:45:48.309: W/System.err(1547):     … 15 more

再去改为:

File extDir = Environment.getExternalStorageDirectory();
String filename = "downloadedMusic.mp3";
File fullFilename = new File(extDir, filename);
 
try {
    fullFilename.createNewFile();
    fullFilename.setWritable(Boolean.TRUE);
    songtaste.stDownloadFromUrl(strSongUrl, fullFilename);
     
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

结果是,可以正常新建文件:

/mnt/sdcard/downloadedMusic.mp3

看来之前就是由于:

/mnt/sdcard:downloadedMusic.mp3

而导致无法创建的。

时间: 2024-11-05 16:07:16

java.io.FileNotFoundException: xxx: open failed: EROFS (Read-only file system)的相关文章

java.io.FileNotFoundException: XXX (系统找不到指定的路径。)

1 import java.io.*; 2 import java.util.Objects; 3 4 public class CSVFile { 5 6 public static void main(String[] args) { 7 String filePath = Objects.requireNonNull(CSVFile.class.getClassLoader().getResource("data.txt")).getPath(); 8 printCSVFile(

【转】idea project中导入其他文件夹下的模块,可能出现java.io.FileNotFoundException: XXX.xml

在一个project 中导入一个java 模块, 我要执行该模块的main函数 ,在main函数中有一个 FileReader(“generatorConfig.xml”) 而generatorConfig.xml就在src下面. 如图 我点执行后却报如下错误: 解决方法:如图我们在 该项目下导入的 模块 vm的位置是 我们的项目下面,而不是这个模块下面.我们要手动设置该类的 工作目录为自己所在的目录位置. 让vm运行位置与其模块所在位置一样 点击ok,重新执行就好了. 转自:https://b

java.io.FileNotFoundException: D:\xxx\yyy (拒绝访问。)问题

File file=new File(fileAllName); FileWriter fw=new FileWriter(file); 在Java的 FileWriter 方法时 系统抛出了异常 java.io.FileNotFoundException: D:\xxx\yyy (拒绝访问.)at java.io.FileOutputStream.open(Native Method)at java.io.FileOutputStream.<init>(FileOutputStream.ja

Android Universal Image Loader java.io.FileNotFoundException: http:/xxx/lxx/xxxx.jpg

前段时间在使用ImageLoader异步加载服务端返回的图片时总是出现 java.io.FileNotFoundException: http://xxxx/l046/10046137034b1c0db0.jpg at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177) at com.nostra13.universalimageloader.core.download.URL

springboot多环境日志配置,启动时logback-test.xml文件冲突导致启动失败:openFile(null,true) call failed. java.io.FileNotFoundException

如题,在项目中用到了4个环境的日志配置文件,启动时在application.properties中指定环境,让springboot自动加载logback对应的配置文件: 每个环境的日志目录都不一样,比如sit和test环境分别是: 如果spring.profiles.active配置的是test,那么一切正常,非test环境,则启动失败.比如我现在配置spring.profiles.active=sit来启动联调环境,报错日志如下: 2020-01-10 14:32:33.579 |-ERROR

Play生产模式下java.io.FileNotFoundException那点事

之前”用Scala+Play构建地理数据查询接口”那篇文章里,用到的数据是json格式的文本文件area.json,存放在conf/jsons文件夹下.最开始是放在public/文件夹下,在线上准生产模式下运行: activator dist 得到mosquito-1.0.zip压缩包,解压后: 去/bin目录下运行mosquito脚本报错: java.io.FileNotFoundException 然后就去解压的mosquito-1.0/看发现并没有public文件夹,由此可见public文

nested exception is java.io.FileNotFoundException: Could not open ServletContext resource

<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> 注意这段配置尽量写在靠前的位置,因为在tomcat启动后web项目会先初始化上下文,我们这段配置正是指定了上下文配置的文件位置,在上下文初始化完成之后才应当继

Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope

1.错误描述 java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99) at org.springframework.test.context.DefaultTestContext.

java.io.FileNotFoundException: antlr-2.7.7.jar (系统找不到指定的路径。)[待解决]

严重: Failed to destroy the filter named [struts2] of type [org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter]java.lang.IllegalStateException: java.io.FileNotFoundException: E:\apache-tomcat-8.0.37\webapps\20170317-JavaEE-SSH\WEB-IN