Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 ?
Posted

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

And then you can read the file like..
Java
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
}
 
Share this answer
 
v2
Comments
hk.v 5-Aug-13 6:14am    
Thanks. Is there any way to read the data, sector wise like from starting 00 to our specified value ?
ridoy 5-Aug-13 6:36am    
i don't think so.
Joezer BH 5-Aug-13 12:13pm    
5ed!
ridoy 5-Aug-13 12:17pm    
Thanks Maimonides,:)
You could try the following code to read the first K of the disk or sdcard.

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


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
 
Share this answer
 
v2
Comments
hk.v 5-Aug-13 7:32am    
Its not working.The following exception is coming..

java.io.FileNotFoundException: /\\.\sdcard0 (No such file or directory)
Joezer BH 5-Aug-13 12:13pm    
5ed!
hk.v 6-Aug-13 2:39am    
How to get the raw data of hard disk using java ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900