Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何读取Xamarin中资产文件夹中的.lcf文件_C#_Xamarin_File Read - Fatal编程技术网

C# 如何读取Xamarin中资产文件夹中的.lcf文件

C# 如何读取Xamarin中资产文件夹中的.lcf文件,c#,xamarin,file-read,C#,Xamarin,File Read,我已将.lcf文件加载到资产文件夹中,并将生成操作设置为内容。我得到一个异常,该文件无法找到 这就是我从assets文件夹中读取.lcf文件并将其存储在字节数组中的方式: byte[] buf = System.IO.File.ReadAllBytes("custom.lcf"); 用于从资源中读取文件 byte[] buffer = new byte[16*1024]; byte[] data; AssetManager assets = this.Assets; using (Strea

我已将
.lcf
文件加载到
资产
文件夹中,并将生成操作设置为
内容
。我得到一个异常,该文件无法找到

这就是我从assets文件夹中读取
.lcf
文件并将其存储在
字节
数组中的方式:

byte[] buf = System.IO.File.ReadAllBytes("custom.lcf");
用于从资源中读取文件

byte[] buffer = new byte[16*1024];
byte[] data;
AssetManager assets = this.Assets;

using (Stream input = assets.Open ("custom.lcf")) {
  using (MemoryStream ms = new MemoryStream())
  {
      int read;
      while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
      {
          ms.Write(buffer, 0, read);
      }
      data = ms.ToArray();
  }
}
用于从资源中读取文件

byte[] buffer = new byte[16*1024];
byte[] data;
AssetManager assets = this.Assets;

using (Stream input = assets.Open ("custom.lcf")) {
  using (MemoryStream ms = new MemoryStream())
  {
      int read;
      while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
      {
          ms.Write(buffer, 0, read);
      }
      data = ms.ToArray();
  }
}
我直接使用了
Assets.Open()
,而不是首先声明对
AssetManager
的引用,但是它的其余部分工作正常,谢谢!我直接使用了
Assets.Open()
,而不是首先声明对
AssetManager
的引用,但是它的其余部分工作正常,谢谢!