如何读取连接到 Android 设备的 USB 闪存的第一个扇区?
我想读取连接到 Android 平板电脑的 USB 闪存的第一个扇区或第一个字节!
我知道应该使用 RandomAccessFile,但我不知道我的 USB 闪存的地址是什么!
感谢您的帮助,
我找到了这段代码,但我不知道应该用什么来代替 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);
}
}
我知道我们应该在 Linux 中使用“/dev/sdaX”,但是对于 adnroid 来说它会是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Android SDK 中不支持“USB 闪存”。请咨询您的设备制造商,了解他们是否有用于访问其设备上的“USB 闪存”的特定协议。
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.