[英]Convert mp4 file to byte array and string
I working on project to upload files into firebase real-time database using firesharp in WinForm c#.我在 WinForm c# 中使用 firesharp 将文件上传到 firebase 实时数据库。
I searched a lot to understand how to do this.我搜索了很多以了解如何执行此操作。
I know about the option to write File.ReadAllBytes(), but I want to run the app on weak PC, with 4 GB ram, and he is very slow.我知道编写 File.ReadAllBytes() 的选项,但我想在性能较差的 PC 上运行该应用程序,内存为 4 GB,而且速度很慢。 I succeeded to upload an image, it's work good.我成功上传了一张图片,效果很好。 I find something about Stram option, but I don't know how to do it with converting to String.我找到了一些关于 Stram 选项的信息,但我不知道如何转换为字符串。
Sorry about my English.对不起我的英语。
You can convert the file to binary, and the binary can be saved as arrays and strings.您可以将文件转换为二进制,二进制可以保存为 arrays 和字符串。
//Read file to byte array
FileStream stream = File.OpenRead(@"c:\path\to\your\file\here.txt");
byte[] fileBytes= new byte[stream.Length];
stream.Read(fileBytes, 0, fileBytes.Length);
stream.Close();
//Begins the process of writing the byte array back to a file
using (Stream file = File.OpenWrite(@"c:\path\to\your\file\here.txt"))
{
file.Write(fileBytes, 0, fileBytes.Length);
}
https://www.codeproject.com/Questions/636646/Csharp-file-to-Byte-Array-and-Byte-Array-to-File https://www.codeproject.com/Questions/636646/Csharp-file-to-Byte-Array-and-Byte-Array-to-File
FileStream st = new FileStream(@"C:\2.jpg", FileMode.Open);
byte[] buffer = new byte[st.Length];
st.Read(buffer, 0, (int)st.Length);
st.Close();
Console.ReadLine();
https://social.msdn.microsoft.com/Forums/en-US/648bd8b2-74ec-4054-9c68-68190b600971/how-to-convert-a-file-to-binary?forum=csharplanguage https://social.msdn.microsoft.com/Forums/en-US/648bd8b2-74ec-4054-9c68-68190b600971/how-to-convert-a-file-to-binary?forum=csharplanguage
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.