Article View: es.comp.os.linux.programacion
Article #8010Re: Leer un fichero
From: alex
Date: Sun, 05 Jan 2003 16:23
Date: Sun, 05 Jan 2003 16:23
48 lines
1904 bytes
1904 bytes
Pues yo tampoco quiero ser menos y voy a publicar una solucion en C#.
<CODIGO>
/* media_en_c#.cs
* Calcula la media, desde los datos que hay en un fichero.
*
* Compilar:
* mcs -o media_en_c#.exe media_en_c#.cs
*
* Ejecutar:
* mono media_en_c#.exe
*/
using System;
using System.IO;
public class CalMedia
{
public static void Main (string[] args)
{
double res = 0;
int cnt = 0;
if (args.Length != 1) {
Console.WriteLine("Usage: media_en_c#.exe <file>");
return;
}
else if (!File.Exists(args[0])) {
Console.WriteLine("Error: No such file: {0}", args[0]);
return;
}
FileStream file = File.Open(args[0], FileMode.Open, FileAccess.Read);
StreamReader reader = new StreamReader(file);
for (string line=reader.ReadLine(); line != null; line=reader.ReadLine()) {
res += (double) Convert.ToInt32(line);
cnt++;
}
Console.WriteLine("Media de los datos en {0} es: {1}", args[0], res/cnt);
file.Close();
}
}
</CODIGO>
Technical Details
Message-ID:
<f8e5025.0301050823.2ea1f349@posting.google.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mailReferences:
<7d4ff0e4.0301020707.6388a1a6@posting.google.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f86c8,5cf283a7acb0d167 X-Google-Attributes: gidf86c8,public X-Google-ArrivalTime: 2003-01-05 08:23:08 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail From: alx78@hotmail.com (alex) Newsgroups: es.comp.os.linux.programacion Subject: Re: Leer un fichero Date: 5 Jan 2003 08:23:08 -0800 Organization: http://groups.google.com/ Lines: 48 Message-ID: <f8e5025.0301050823.2ea1f349@posting.google.com> References: <7d4ff0e4.0301020707.6388a1a6@posting.google.com> NNTP-Posting-Host: 80.103.116.182 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1041783788 6980 127.0.0.1 (5 Jan 2003 16:23:08 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 5 Jan 2003 16:23:08 GMT