如何读取连接到 Android 设备的 USB 闪存的第一个扇区?

发布于 2025-01-01 18:38:21 字数 1336 浏览 1 评论 0原文

我想读取连接到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

错々过的事 2025-01-08 18:38:21

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文