ficheros c#
Publicado por alex (10 intervenciones) el 25/02/2006 12:03:22
como puedo crear ficheros para guardar informacion?
he probado este, pero no veo q se cree ningun archivo
public static void leerFich()
{
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);
}
TAMBIEN HE PROBADO CON ESTO
public static void leerFich()
{
private const string FILE_NAME = "MyFile.txt";
public static void Main(String[] args)
{
if (File.Exists(FILE_NAME))
{
Console.WriteLine("{0} already exists.", FILE_NAME);
return;
}
StreamWriter sr = File.CreateText(FILE_NAME);
sr.WriteLine ("This is my file.");
sr.WriteLine ("I can write ints {0} or floats {1}, and so on.",
1, 4.2);
sr.Close();
}
}
SE SUPONE QUE DONDE SE CREARIAN LOS FICHEROS???
AHH¡¡ Y SI LO QUE QUIERO GUARDAR SON OBJETOS, COMO LO HARIA?
A VER SI ALGUIEN ME HECHA UN CABLE.
O ME EXPLICA BASICAMENTE CMO LO TENGO QUE HACER.
gracias
he probado este, pero no veo q se cree ningun archivo
public static void leerFich()
{
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);
}
TAMBIEN HE PROBADO CON ESTO
public static void leerFich()
{
private const string FILE_NAME = "MyFile.txt";
public static void Main(String[] args)
{
if (File.Exists(FILE_NAME))
{
Console.WriteLine("{0} already exists.", FILE_NAME);
return;
}
StreamWriter sr = File.CreateText(FILE_NAME);
sr.WriteLine ("This is my file.");
sr.WriteLine ("I can write ints {0} or floats {1}, and so on.",
1, 4.2);
sr.Close();
}
}
SE SUPONE QUE DONDE SE CREARIAN LOS FICHEROS???
AHH¡¡ Y SI LO QUE QUIERO GUARDAR SON OBJETOS, COMO LO HARIA?
A VER SI ALGUIEN ME HECHA UN CABLE.
O ME EXPLICA BASICAMENTE CMO LO TENGO QUE HACER.
gracias
Valora esta pregunta


0