how can i read first sector of a USB flash connected to a android device?

698 views Asked by At

i want to read the first sector or first bytes of a USB flash which is connected to a android tablet!

i know that is should use RandomAccessFile, but i don't know what is the address to my USB flash!

thanks for your help


i have found this code but i don't know what should i put instead of args[0]

public class FAT16
{
public static void main(String[] args) throws IOException
{
// open file whose name is on the command line for input

RandomAccessFile file = new RandomAccessFile(args[0], "r");

// skip ahead to byte 19 (0x13 hex) where the num of sectors is stored

file.seek(0x13);

// 2-byte values are little-endian; Java is big-endian, so we
// have to read the two bytes separately and glue them together
// ourselves

int low = file.readUnsignedByte();
int high = file.readUnsignedByte();

int sectorsOnDisk = low + (high * 256);

// skip ahead to where the sectors per FAT is stored

file.seek(0x16);
low = file.readUnsignedByte();
high = file.readUnsignedByte();

int sectorsPerFAT = low + high * 256;

// skip back to where the bytes per sector is stored

file.seek(0x0b);
low = file.readUnsignedByte();
high = file.readUnsignedByte();
int bytesPerSector = low + high * 256;

// report size of disk and number of sectors per FAT

System.out.println("Disk size = " + sectorsOnDisk * bytesPerSector );
System.out.println("Sectors per FAT = " + sectorsPerFAT);
}

}

i know that we should use "/dev/sdaX" in linux, but what it would be for adnroid?

1

There are 1 answers

2
CommonsWare On

There is no support for "a USB flash" in the Android SDK. Please consult with your device manufacturer to see if they have specific protocols for accessing "a USB flash" on their devices.