Jak przekonwertować system struct.Bajt bajt [] do obiektu System.IO. Stream w C#?
Jak przekonwertować strukturę System.Byte
byte[]
do System.IO.Stream
obiektu w C#?
569
Author: Olorunfemi Ajibulu, 2011-01-19
4 answers
Najprostszym sposobem konwersji tablicy bajtów na strumień jest użycie MemoryStream
klasa:
Stream stream = new MemoryStream(byteArray);
978
Author: Martin Buberl,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-02-23 10:59:00
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-02-23 10:59:00
Szukasz MemoryStream.Write
metoda . na przykład poniższy kod zapisze zawartość tablicy byte[]
do strumienia pamięci:
byte[] myByteArray = new byte[10];
MemoryStream stream = new MemoryStream();
stream.Write(myByteArray, 0, myByteArray.Length);
Alternatywnie, możesz utworzyć nowy , nie zmieniający rozmiaru MemoryStream
Obiekt na podstawie tablicy bajtów:
byte[] myByteArray = new byte[10];
MemoryStream stream = new MemoryStream(myByteArray);
284
Author: Cody Gray,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-01-19 14:11:14
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-01-19 14:11:14
Ogólne podejście do zapisu do dowolnego strumienia (nie tylko MemoryStream
) polega na użyciu BinaryWriter
:
static void Write(Stream s, Byte[] bytes)
{
using (var writer = new BinaryWriter(s))
{
writer.Write(bytes);
}
}
25
Author: QrystaL,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-08-09 20:14:18
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-08-09 20:14:18
Zajrzyj do MemoryStream
klasy.
4
Author: Corey Ogburn,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-08-20 05:03:02
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-08-20 05:03:02