首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C#从EXT4 SD卡写入和读取文件

C#从EXT4 SD卡写入和读取文件
EN

Stack Overflow用户
提问于 2021-02-28 20:24:35
回答 1查看 391关注 0票数 0

我有一个树莓派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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-02 05:09:20

SharpExt4可以帮助你读写Linux文件系统。

提供对Linux ext2/ext3/ext4文件系统的完全访问(读/写)的.Net库

这是GitHub链接https://github.com/nickdu088/SharpExt4

代码语言:javascript
复制
//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();

How to use SharpExt4 to access Raspberry Pi SD Card Linux partition

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66409065

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档