Azure Data Lake Store .NET SDK 可以读写二进制文件吗?
Can Azure Data Lake Store .NET SDK read and write binary files?
ADLS .NET SDK 有一些很好的读取和创建文本文件的示例。这使用 StreamReader 并且不应与二进制文件一起使用。我尝试使用 BinaryReader 但没有成功。
https://docs.microsoft.com/en-us/azure/data-lake-store/data-lake-store-data-operations-net-sdk
//Read file contents
using (var readStream = new StreamReader(client.GetReadStream(fileName)))
{
string line;
while ((line = readStream.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
.NET SDK create/read 二进制文件可以吗?如果是这样,有没有这样做的例子?
Can the .NET SDK create/read binary? If so, are there any examples of doing this?
简答是的,请参考下面的演示代码。
创建二进制文件
AdlsClient adlsClient = AdlsClient.CreateClient($"{datalakeAccount}.azuredatalakestore.net", clientCreds);
using (var stream = adlsClient.CreateFile("file name", IfExists.Overwrite))
{
byte[] textByteArray = File.ReadAllBytes(@"local file path");
stream.Write(textByteArray, 0, textByteArray.Length);
}
读取二进制文件并写入本地文件
using (var filesream = adlsClient.GetReadStream("1.png"))
{
MemoryStream memorystream = new MemoryStream();
filesream.CopyTo(memorystream);
memorystream.Position = 0;
File.WriteAllBytes(@"filename", memorystream.ToArray());
}
ADLS .NET SDK 有一些很好的读取和创建文本文件的示例。这使用 StreamReader 并且不应与二进制文件一起使用。我尝试使用 BinaryReader 但没有成功。
https://docs.microsoft.com/en-us/azure/data-lake-store/data-lake-store-data-operations-net-sdk
//Read file contents
using (var readStream = new StreamReader(client.GetReadStream(fileName)))
{
string line;
while ((line = readStream.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
.NET SDK create/read 二进制文件可以吗?如果是这样,有没有这样做的例子?
Can the .NET SDK create/read binary? If so, are there any examples of doing this?
简答是的,请参考下面的演示代码。
创建二进制文件
AdlsClient adlsClient = AdlsClient.CreateClient($"{datalakeAccount}.azuredatalakestore.net", clientCreds);
using (var stream = adlsClient.CreateFile("file name", IfExists.Overwrite))
{
byte[] textByteArray = File.ReadAllBytes(@"local file path");
stream.Write(textByteArray, 0, textByteArray.Length);
}
读取二进制文件并写入本地文件
using (var filesream = adlsClient.GetReadStream("1.png"))
{
MemoryStream memorystream = new MemoryStream();
filesream.CopyTo(memorystream);
memorystream.Position = 0;
File.WriteAllBytes(@"filename", memorystream.ToArray());
}