Principales respuestas
Guardar un Objeto Stream en el sistema de archivos

Pregunta
-
Buenas,
Tengo un objeto de tipo Stream.Este objeto ya tiene todo elcontenido del archivo. Lo que quiero ahora es guardar el archivo contenido en el Stream en el sistema de archivos, pero no veo ningun metodo para ello. Todo lo asociado al guardado está para FileStream o WriteStream y trabajan con bytes, no veo nada para la clase Stream.¿Alguien me puede ayudar?
Gracias de antemano.
Respuestas
-
Tendrías que utilizar StreamWriter.
http://msdn.microsoft.com/es-es/library/system.io.streamwriter(VS.80).aspx
Code Snippet
// Create an instance of StreamWriter to write text to a file.
// The using statement also closes the StreamWriter.
using (StreamWriter sw = new StreamWriter("TestFile.txt"))
{
// Add some text to the file.
sw.Write("This is the ");
sw.WriteLine("header for the file.");
sw.WriteLine("-------------------");
// Arbitrary objects can also be written to the file.
sw.Write("The date is: ");
sw.WriteLine(DateTime.Now);
}Tienes muchos ejemplos de entrada y salida en MSDN.
http://msdn.microsoft.com/es-es/library/k3352a4t(VS.80).aspx
Otro buen ejemplo
http://www.elguille.info/NET/dotnet/leer_escribir_ficheros_texto.htm
Si la respuesta ha sido de utilidad marca la como correcta.
Saludos.
Todas las respuestas
-
Tendrías que utilizar StreamWriter.
http://msdn.microsoft.com/es-es/library/system.io.streamwriter(VS.80).aspx
Code Snippet
// Create an instance of StreamWriter to write text to a file.
// The using statement also closes the StreamWriter.
using (StreamWriter sw = new StreamWriter("TestFile.txt"))
{
// Add some text to the file.
sw.Write("This is the ");
sw.WriteLine("header for the file.");
sw.WriteLine("-------------------");
// Arbitrary objects can also be written to the file.
sw.Write("The date is: ");
sw.WriteLine(DateTime.Now);
}Tienes muchos ejemplos de entrada y salida en MSDN.
http://msdn.microsoft.com/es-es/library/k3352a4t(VS.80).aspx
Otro buen ejemplo
http://www.elguille.info/NET/dotnet/leer_escribir_ficheros_texto.htm
Si la respuesta ha sido de utilidad marca la como correcta.
Saludos.
-
Gracias, pero ya habñia visto esa documentación. Pero no soluciona el problema. Tengo un Objeto Stream ya creado, y en la documentación dice que tengo que crear otro, pero ¿como vuelco la información mediante un buffer? No lo veo como una solución valida.
-
Pues entonces si no quieres trabajar con bytes te tienes que plantear la forma de recuperar el fichero.
Stream Proporciona una vista genérica de una secuencia de bytes.
http://msdn.microsoft.com/es-es/library/system.io.stream(VS.80).aspx
Tienes diferentes clases para elegir trabajar con bytes o directamente con texto.
http://msdn.microsoft.com/es-es/library/ms404278(VS.80).aspx
Un Saludo.