file handle

05/10/2004 - 19:55 por kode | Informe spam
Hola como se hace para abrir un archivo y obtener el
handle?

gracias
 

Leer las respuestas

#1 Braulio Diez
06/10/2004 - 09:40 | Informe spam
Hola !

Mmm... que es lo que quieres hacer con el archivo y el
handle ? Ahora en .net para leer y escribir archivos se
usan los streamReader y writers y FileStream, aquí te va
un ejemple que juega con esto (si te hace falta hacer
algo especial con ese handle ponlo por aquí y a ver si lo
sacamos ;-)):

[C#]
using System;
using System.IO;
using System.Text;

class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";

// Delete the file if it exists.
if (!File.Exists(path))
{
// Create the file.
using (FileStream fs = File.Create(path))
{
Byte[] info = new UTF8Encoding
(true).GetBytes("This is some text in the file.");

// Add some information to the file.
fs.Write(info, 0, info.Length);
}
}

// Open the stream and read it back.
using (FileStream fs = File.Open(path,
FileMode.Open, FileAccess.Read, FileShare.None))
{
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);

while (fs.Read(b,0,b.Length) > 0)
{
Console.WriteLine(temp.GetString(b));
}

try
{
// Try to get another handle to the same
file.
using (FileStream fs2 = File.Open(path,
FileMode.Open))
{
// Do some task here.
}
}
catch (Exception e)
{
Console.Write("Opening the file twice is
disallowed.");
Console.WriteLine(", as expected: {0}",
e.ToString());
}
}
}
}


Buena suerte
Braulio


Hola como se hace para abrir un archivo y obtener el
handle?

gracias
.

Preguntas similares