new FileOutputStream("a.bmp") 报错java.io.FileNotFoundException: /a.bmp (Read-only file system)

智能音箱麦克风阵列实战:Python实现宽带GSC波束形成(附完整代码) 本文从工程实战角度,详细介绍了如何在智能音箱中利用Python实现宽带GSC波束形成算法。文章深入解析了广义旁瓣消除器(GSC)的核心架构,包括固定波束形成、阻塞矩阵与自适应滤波路径,并提供了完整的仿真代码、关键参数(如LMS步长)调优方法,以及面向嵌入式部署的计算优化与移植考量,旨在帮助开发者构建在真实噪声环境下高效工作的语音增强系统。 阅读详情
03-20 14:10:36.971 4270-4297/? W/System.err: java.io.FileNotFoundException: /a.bmp (Read-only file system)
03-20 14:10:36.981 4270-4297/? W/System.err:     at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
03-20 14:10:36.981 4270-4297/? W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
03-20 14:10:36.981 4270-4297/? W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
03-20 14:10:36.981 4270-4297/? W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:144)
03-20 14:10:36.991 4270-4297/? W/System.err:     at tech.androidstudio.readfileshttpurlconnection.MainActivity.run(MainActivity.java:43)

03-20 14:10:36.991 4270-4297/? W/System.err:     at java.lang.Thread.run(Thread.java:1019)


原因分析:

注意报错里面的信息为,不能创建主目录/ 下面的a.bmp ,这是一个只读的文件夹。所以说文件的路径有问题,

我的代码如下,错误就是没有写路径

fos = new FileOutputStream("a.bmp");

解决方法:

将路径添加进去,例如添加到cache的文件夹里面

//下面存储到内部存储的私有的cache目录里面,注意了生成的文件名是cachea.bmp
fos = new FileOutputStream(getCacheDir().getPath()+"a.bmp");

package tech.androidstudio.readfileshttpurlconnection;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;

public class MainActivity extends AppCompatActivity implements Runnable {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Thread thread = new Thread(this);
        thread.start();
    }

    @Override
    public void run() {
        try {
            //TODO 这里的ip 地址一定不能使localhost 一定要是电脑的或者是正式ip地址.
            //如果写成了localhost,那么就会报错java.net.ConnectException: localhost/127.0.0.1:8080 - Connection refused
//            URL url = new URL("http://localhost:8080/tomcat.png");
            URL url = new URL("http://192.168.1.106:8080/tomcat.png");
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
            httpURLConnection.setRequestMethod("GET");
            httpURLConnection.setConnectTimeout(5000);
            //Sets the flag indicating whether this URLConnection allows input. It cannot be set after the connection is established.
            httpURLConnection.setDoInput(true);

            InputStream in = null;
            FileOutputStream fos = null;
            if (httpURLConnection.getResponseCode() == 200) {
                in = httpURLConnection.getInputStream();
                //一定不能直接在FileOutputStream里面写文件名,需要添加路径
                //错误的写法:fos = new FileOutputStream("a.bmp");
                //下面存储到内部存储的私有的cache目录里面,注意了生成的文件名是cachea.bmp
                fos = new FileOutputStream(getCacheDir().getPath()+"a.bmp");
                byte[] arr = new byte[1024];
                int len = 0;
                while ((len = in.read(arr)) != -1) {
                    fos.write(arr, 0, len);
                }
                in.close();
                fos.close();
            }

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (ProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



Windows 10/11下R与RStudio最新版安装避坑指南(含镜像加速配置) 本文提供了Windows 10/11系统下R与RStudio最新版的详细安装指南,包含镜像加速配置和常见问题解决方案。通过分步教程帮助用户避开安装陷阱,优化开发环境设置,特别适合国内用户快速搭建高效的数据分析平台。 阅读详情

相关推荐

离线语音识别模块LD3320实战:如何低成本给STM32设备加上‘耳朵’和‘嘴巴’?

本文详细介绍了如何为STM32设备集成LD3320离线语音识别模块,实现低成本语音交互方案。从硬件连接到STM32底层驱动实现,再到指令训练与词条优化技巧,完整解析了唤醒词检测与自定义指令识别的全过程。LD3320作为非特定人声识别芯片,无需网络连接,适用于智能家居、工业控制等场景,是嵌入式开发者的理想选择。

weixin_30906185的博客 555

关于 new FileOutputStream(file) 异常问题 :FileNotFoundException

在创建文件输出流时 一定得保证 文件夹! 文件夹! 文件夹! 存在。 即在 newFileOutputStream(file);之前 先调用 mkdirs()方法: 创建代码如下: File foder = new File(FileUtils.getRootDirectory()+ "/updateVersion/"); if (!foder.exists()) { fo...

qq_36366065的博客 1万+

CSAPP performance lab

CSAPP 深入理解计算机系统的performance Lab

weixin_46091531的博客 1250

FileOutputStream全路径报错

今天排查测试环境问题,发现后台日志报错:FileNotFoundException,这个功能是从FastDFS上拉取文件到本地。调用了fastdfs的download_file方法下载文件。 其中片段代码: 经断点调试。发现FileOutputStream ex1 = new FileOutputStream(local_filename);报错FileNotFoundException异常。 ...

liangruiwei_kook的博客 3877

海康Camera MVS Linux SDK二次开发封装ROS packge过程记录(c++)

https://www.hikrobotics.com/machinevision/service/download?module=0

weixin_41965898的博客 2万+

SAP 公司间采购简介

SAP公司间采购(Intercompany Procurement)是指企业集团内部不同法人实体之间的采购和销售流程。这种流程在跨国公司或有多个独立运营子公司的企业中非常常见。SAP提供了标准的功能来处理公司间采购,确保财务和物流流程的透明性和效率。以下是SAP公司间采购的基本流程及其相关模块的简介。

我小时候很黑的博客 1376

异常 (一)

异常的处理:抓抛模式

z1341586646的博客 543

常用元器件使用方法13:物理层接口芯片DP83848的使用方法

介绍: DP83848是以太网物理层接口芯片,具有多种型号,从便于焊接角度考虑LQFP-48封装较为合适,采用LQFP-48封装的芯片,有2种型号,分别为DP83848I和DP83848C,如下图所示。 其主要区别是使用温度不同,如下图所示。 这2种芯片芯片网上均有销售,按理说DP83848C价格应该更加便宜,实际不然,DP83848I的价格低于DP83848C,考虑或与芯片的出货量...

snmplink的博客 1万+

java使用File写入文件出现java.io.FileNotFoundException错误解决办法(无法生成文件而是生成目录)

java使用File写入文件出现java.io.FileNotFoundException错误解决办法(无法生成文件而是生成目录) java.io.FileNotFoundException错误解决(使用!f.isDirectory()判断) 入坑许久,这个错误让我头疼了一下午。当我们使用File类创建文件时,会遇见被拒绝访问的错误异常。本人在网上搜索基本都是后缀名没有添加,但是这也无法解决本人问题(磁盘写入权限已检查,没有问题),以致我认为是电脑出现了问题。但在我仔细检查后,发现是方法逻辑问题。 错误代码

Liu_Yuntian的博客 1万+

《Zephyr OS 入门与实战》第5章:内存管理策略

【代码】《Zephyr OS 入门与实战》第5章:内存管理策略。

2301_79143213的博客 349

鸢尾花分类预测

鸢尾花数据总用有150个样本,是一个典型的分类数据集,共有3个类别,分别是山鸢尾(Iris-setosa)、变色鸢尾(Iris-versicolor)和维吉尼亚鸢尾(Iris-virginica),每个样本的特征有4列sepal_length:萼片长度sepal_width:萼片宽度petal_length:花瓣长度petal_width:花瓣宽度这里我们定义了随机森林模型作为实例,来进行模型训练,之后我们会对其使用网格搜索找到最优的参数。

优快云 精品推荐 2188

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

在聊天中发视屏的时候,需要获取视屏某一帧的图片,以文件形式上传给服务器,然后就出了这个错。 在确定文件读取权限都有的情况下,那么很可能就是路径不对一看果然:String filePah = System.currentTimeMillis() + ".png";这个是很粗心的没有带上根目录,就是说,创建的file的时候,如果file.create(),或者 new File(filePath),操

jiahuan 1万+

SAP生产订单技术性完成(TECO)操作指南与实战应用

生产订单技术关闭操作指南主要包括单笔和批量关闭两种方式,通过CO02/COHV事务码完成。

m0_47402127的博客 1932

Springboot文件操作

Springboot文件操作

yyb1369584682的博客 1030

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

编译出现报错该怎么办!!!???

如果Java打开文件的时候,没有关闭IO流,那么打开到一定数量,在Linux下就会抛出Too many open files的异常。如果超过了最大允许打开文件数量的限制,需要修改系统的open files数值限制,可以通过运行。注意,这种修改方法在重启后会还原为默认值,需要进行永久设置。来查看当前设置,其中 open files (-n) 表示每个用户最大允许打开的文件数量。需要注意的是,在修改完毕配置文件之后需要重启系统才能生效。首先需要了解每个用户最大允许打开的文件数量,可以通过运行。

强国豪,林中霖 159

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

android fileoutputstream 权限,关于ioexception:Android Studio内部存储FileOutputStream FileNotFound...

我正在android studio上工作,我想在内部存储中写入/存储文件。 我知道在堆栈溢出时有几个类似的问题。 我设法从这些代码中获取了这些代码。public static void writeObj(Alarm alarm, Context context){FileOutputStream fos = null;ObjectOutputStream oos = null;try{fos = ...

weixin_30041067的博客 924

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

android的java文件存储在哪_【已解决】Android中的文件存储位置:java.io.FileNotFoundException: xxx: open failed: EROFS (Read...

【问题】折腾:的过程中,出错: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...

weixin_35869861的博客 1006

OutputStream创建文件时报错java.io.FileNotFoundException解决办法

OutputStream从内存到硬盘写入数据 文件不存在 输出流会自动创建这样一个文件 但是遇到如图错误: 发现OutputStream可以创建文件,但是不能创建多级目录下的文件,如果要创建多级目录下的文件,可以先创建目录,文件是可以自动创建的 File file=new File("E:\\newFile\\hello.jpeg"); File dir=new Fil...

tcbdbd的博客 3216

【总结】关于fileoutputstream应用中的FileNotFoundException问题的解决办法

在使用fileoutputstream时经常出现FileNotFoundException问题,即便是同一个程序改了一下包名再chongxin

KK的专栏 2万+

打开Openfire 关于出现 java.io.FileNotFoundException: 等错误信息

出现这种问题的解决方案是,需要使用管理员的身份打开opnefire

Android移动开发 1088

fileoutputstream 抛文件找不到异常

今天使用fileoutputstream的时候, 抛了文件找不到异常:FileNotFoundException 我们知道, 使用new Fileoutputstream(filepath)时, 如果filepath指定的文件不存在, 文件输出流会帮我们自动创建一个文件。仅仅是文件而已。 如果filepath中包含尚未创建的目录, 就会抛出文件找不到异常。 所以在使用输出流之前, 最好使用Fil

zona 1万+

(完美解决)java文件操作报错:java.io.FileNotFoundException(拒绝访问)

01-错误信息: Exception in thread "main" java.io.FileNotFoundException: e:b (拒绝访问。) at java.io.FileOutputStream.open0(Native Method) at java.io.FileOutputStream.open(Unknown Source) at java.io.FileOutputStream.<init>(Unknown Source) at java.io.FileOu

m0_61083409的博客 3万+

JavaIO流遇到的一个坑(FileOutputStream找不到文件)

所以,必须要先用mkdirs();方法创建多级目录,然后再用file.createNewFile()方法.FileOutputStream会自动创建文件,但是如果是多级目录,就创建不了并且报错。所以,必须要先创建文件夹,之后才能用FileOutputStream。这里注意createNewFile()方法也不能创建多级目录的文件。在读取zip文件时,如果有中文名称的文件夹,会报错。此时,只需要修改一下字符编码就好了.

weixin_42795208的博客 6349

处理FileOutputStream异常

public class IOException {     public static void main(String[] args) {         // 1.建立输出流对象         // 2.处理异常         FileOutputStream fos = null;         try {             File file = new File("e:d....

qq_41815040的博客 2195

java文件操作报错:java.io.FileNotFoundException:D:\..(拒绝访问)

import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.Outpu...

wjkwan的博客 9万+

java复制文件拒绝访问权限_关于IO流在复制文件时出现java.io.FileNotFoundException: D:\xxx (拒绝访问。) 拒绝访问的问题...

关于IO流在复制文件时出现java.io.FileNotFoundException: D:\xxx(拒绝访问。)拒绝访问的问题Exception in thread "main"java.io.FileNotFoundException: D:\xxx(拒绝访问。)at java.io.FileInputStream.open0(Native Method)at java.io.FileInpu...

weixin_32911063的博客 3559
上一篇: httpURLConnection 报错 java.net.ConnectException: localhost/127.0.0.1:8080 - Connection refused
下一篇: Android 中HttpURLConnection 的使用
千雅爸爸
博客等级 码龄18年 292粉丝 639原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值