[英]C# write and read files from an EXT4 SD Card
我有一个 Raspberry Pi SD 卡,它有 2 个分区,第一个是 Fat32,第二个是 EXT4 分区,现在我想访问 C# 中 EXT4 分区上的文件来写入、编辑、读取和创建文件。 我已经用 System.IO 尝试了一些东西来获取目录等(非常基本的东西)。 那么有谁知道是否有办法使用 C# 代码访问 EXT4 分区/磁盘?
我正在使用 Windows 10 操作系统。
它应该像这样工作: File.Create("path to the Disk(J:)/rootfs/home/pi/file.conf");
但是,我收到一个错误: System.IO.IOException: "There is no recognized file system on the data carrier
SharpExt4 可以帮助您读写 Linux 文件系统。
A.Net 库提供对 Linux ext2/ext3/ext4 文件系统的完全访问(读/写)
这是 GitHub 链接https://github.com/nickdu088/SharpExt4
//Open EXT4 SD Card
//Here is SD Card physical disk number. you can get from Windows disk manager
ExtDisk SharpExt4.ExtDisk.Open(int DiskNumber);
//In your case FAT32 is 1st one, ext4 is 2nd one
//Open EXT4 partition
var fs = ExtFileSystem.Open(disk.Parititions[1]);
//Create /home/pi/file.conf file for write
var file = fs.OpenFile("/home/pi/file.conf", FileMode.Create, FileAccess.Write);
var hello = "Hello World";
var buf = Encoding.ASCII.GetBytes(hello);
//Write to file
file.Write(buf, 0, buf.Length);
file.Close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.