Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. collections;
Using system. IO;
Using system. text;
/// <Summary>
/// Summary description for readfile
/// </Summary>
Public class readfile
{
Public readfile ()
{
//
// Todo: Add constructor logic here
//
}
Public int [,] readfiletoarray ()
{
Int [,] iret = NULL;
Arraylist alnumline = getfilecontent ();
String [] strlinearr = NULL;
If (alnumline. Count> 0)
{
Strlinearr = convert. tostring (alnumline [0]). Trim (','). Split (',');
Iret = new int [alnumline. Count, strlinearr. Length];
For (INT I = 0; I <alnumline. Count; I ++)
{
Strlinearr = convert. tostring (alnumline [I]). Trim (','). Split (',');
For (Int J = 0; j <strlinearr. length; j ++)
{
Iret [I, j] = convert. toint32 (strlinearr [J]);
}
}
}
Return iret;
}
Public arraylist getfilecontent ()
{
Arraylist alret = new arraylist ();
String strfilepath = httpcontext. Current. server. mappath ("~ ") +"/Array.txt ";
If (! File. exists (strfilepath ))
{
Httpcontext. Current. response. Write ("file [" + strfilepath + "] does not exist. ");
Return alret;
}
Try
{
// Read a line of text and temporarily store it in the arraylist
Streamreader sr = new streamreader (strfilepath, encoding. getencoding ("gb2312 "));
String L;
While (L = Sr. Readline ())! = NULL)
{
If (! String. isnullorempty (L. Trim ()))
Alret. Add (L. Trim ());
}
Sr. Close ();
}
Catch (ioexception ex)
{
Httpcontext. Current. response. Write ("An error occurred while reading the file! Check whether the file is correct. ");
Httpcontext. Current. response. Write (ex. tostring ());
}
Return alret;
}
}