如何访问SD卡上的特定原始数据? [英] How to access specific raw data on SD card?

查看:90
本文介绍了如何访问SD卡上的特定原始数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个Android项目。在这个项目中,我需要逐个扇区地阅读SD卡的数据。我试过在某些方面,比如



RandomAccessFile file = new RandomAccessFile(\\ \\\\\\PhysicalDrive0,r);

但Filenotfound异常即将到来。我在MFC(VC ++)中做过类似的项目。通过使用Handle,CreateFile和ReadFile函数,我正在阅读数据扇区。 java中有哪些函数可以按扇区读取数据?

I am doing an Android project. In this project i need to read the data of SD card sector by sector.I tried in some ways , Like

RandomAccessFile file = new RandomAccessFile("\\\\.\\PhysicalDrive0","r");
But Filenotfound Exception is coming. I did a similar kind of project in MFC(VC++). There by using Handle, CreateFile nad ReadFile functions i am reading the data sector wise. Any functions are there in java to read the data sector by sector ?

推荐答案

你想从SD卡中读取数据。所以做一些事情像这样...

You want to read data from sd card.So do something like this...
File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, "path_of_your_file");



然后你就可以读取文件了......


And then you can read the file like..

fileIS = new FileInputStream(yourFile);
BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));
String readString = new String();
//just reading each line and pass it on the debugger
while((readString = buf.readLine())!= null){
   //readString has your data
}


您可以尝试以下代码来读取第一个K磁盘或SD卡。



You could try the following code to read the first K of the disk or sdcard.

File diskRoot = new File ("\\\\.\\PhysicalDrive0");
RandomAccessFile diskAccess = new RandomAccessFile (diskRoot, "r");
byte[] content = new byte[1024];
diskAccess.readFully (content);





不要忘记需要更改PhysicalDrive0,在Windows上它会是'C'或'D'和你需要管理员权限。在Android上尝试'sdcard0'和一些手机的'extSDCard'。



我没有尝试过,所以让我知道它是否有效。



/ Darren



Don't forget PhysicalDrive0 needs to be changed, On windows it would be 'C' or 'D' and you will require admin privs. On Android try 'sdcard0' and some phones 'extSDCard'.

I've not tried it, so let me know if it works.

/Darren


这篇关于如何访问SD卡上的特定原始数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆