如何在 CosmosOS 中保存数据?
How to save data in CosmosOS?
我正在研究 Cosmos 操作系统,我想知道是否有某种方法可以写入包含信息的文件?我正在尝试让 CosmosOS 提醒用户名和密码。
PS。我也不希望它能够 读取 文件。
目前只支持FAT,所以你至少需要一个FAT分区。在您的 BeforeRun
方法中,您需要初始化 VFS,如下所示:
var fs = new Sys.FileSystem.CosmosVFS();
Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);
然后就可以使用System.IO
API 来读写文件了。第一个分区的根路径是 0:\
.
例子
public override void BeforeRun()
{
var fs = new Sys.FileSystem.CosmosVFS();
Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);
}
public override void Run()
{
var usersFile = @"0:\users.dat";
if (!File.Exists(usersFile))
{
File.Create(usersFile);
}
// now you can read or write to the file
// example read methods: File.ReadAllText, File.ReadAllLines, File.ReadAllBytes
// example write methods: File.WriteAllText, File.WriteAllLines, File.WriteAllBytes
}
我遇到了同样的问题,这对我有用
using Cosmos.System.FileSystem;
var usersFile = @"0:\users.dat";
public static CosmosVFS FAT = new CosmosVFS();
FAT.CreateFile(usersFile );
我正在研究 Cosmos 操作系统,我想知道是否有某种方法可以写入包含信息的文件?我正在尝试让 CosmosOS 提醒用户名和密码。
PS。我也不希望它能够 读取 文件。
目前只支持FAT,所以你至少需要一个FAT分区。在您的 BeforeRun
方法中,您需要初始化 VFS,如下所示:
var fs = new Sys.FileSystem.CosmosVFS();
Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);
然后就可以使用System.IO
API 来读写文件了。第一个分区的根路径是 0:\
.
例子
public override void BeforeRun()
{
var fs = new Sys.FileSystem.CosmosVFS();
Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);
}
public override void Run()
{
var usersFile = @"0:\users.dat";
if (!File.Exists(usersFile))
{
File.Create(usersFile);
}
// now you can read or write to the file
// example read methods: File.ReadAllText, File.ReadAllLines, File.ReadAllBytes
// example write methods: File.WriteAllText, File.WriteAllLines, File.WriteAllBytes
}
我遇到了同样的问题,这对我有用
using Cosmos.System.FileSystem;
var usersFile = @"0:\users.dat";
public static CosmosVFS FAT = new CosmosVFS();
FAT.CreateFile(usersFile );