问题
I'm working on a Cosmos operatingsystem, and I'm wondering if there is some way to write a file with information in it? I'm trying to make CosmosOS remind the username and the password.
PS. I also wan't it to be able to read the file.
回答1:
Currently only FAT is supported, so you need at least one FAT partition. In your BeforeRun
method, you need to initialize the VFS, like this:
var fs = new Sys.FileSystem.CosmosVFS();
Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);
Then you can use the System.IO
APIs to read and write files. The root path for the first partition is 0:\
.
Example
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
}
回答2:
I had the same issue this worked for me
using Cosmos.System.FileSystem;
var usersFile = @"0:\users.dat";
public static CosmosVFS FAT = new CosmosVFS();
FAT.CreateFile(usersFile );
来源:https://stackoverflow.com/questions/50100827/how-to-save-data-in-cosmosos