android 读取文件二进制文件,从Android上的二进制文件中读取
发布日期:2021-06-24 17:13:16 浏览次数:2 分类:技术文章

本文共 1273 字,大约阅读时间需要 4 分钟。

我有一些使用Matlab保存到文件中的数据。我已经在Matlab中保存了这些数据,如下所示:

fwrite(fid,numImg2,'integer*4');

fwrite(fid,y,'integer*4');

fwrite(fid,imgName,'char*1');

fwrite(fid,a,'integer*4');

fwrite(fid,img.imageData,'double');我使用下面的代码将这些数据读回Matlab

fread(fid,1,'integer*4');// Returns numImg2

fread(fid,1,'integer*4');// Returns y which is the number of cha rectors in the image name, i use in the following line to read the image name, say for example if the image name is 1.jpg, then using the following will return the image name

fread(fid,5,'char*1');

fread(fid,1);

etc...我希望能够在android手机上阅读这些数据。这是我目前的代码。

DataInputStream ds = new DataInputStream(new FileInputStream(imageFile));

//String line;

// Read the first byte to find out how many images are stored in the file.

int x = 0;

byte numberOfImages;

int numImages = 0;

while(x<1)

{

numberOfImages = ds.readByte();

numImages = (int)numberOfImages;

x++;

}

int lengthName = 0;

String imgName = "";

for(int y=1; y<=numImages; y++)

{

lengthName = ds.readInt();

byte[] nameBuffer = new byte[lengthName];

char[] name = new char[lengthName];

for(int z = 1; z<=5;z++)

{

nameBuffer[z-1] = ds.readByte();

//name[z-1] = ds.readChar();

}

imgName = new String(nameBuffer);

//imgName = name.toString();

}

text.append(imgName);我似乎无法从二进制文件数据中检索图像名称作为字符串。任何帮助深表感谢。

转载地址:https://blog.csdn.net/weixin_34017915/article/details/117579537 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:html表格打印重叠,html的table打印注意事项
下一篇:android 奔跑加载动画,VUE 教程 动画过度

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月01日 00时57分05秒