aspx を使用してテキスト ファイルを読み込もうとしていて、読み込んだ行を文字列に格納しようとしています。
2 に答える
1
ファイルがサーバー上の既知の場所に配置されたら、次の手順を実行するだけです。
string filePath = Server.MapPath(Url.Content("~/Content/upload/MyTextFile.txt"));
string allText = System.IO.File.ReadAllText(filepath);
于 2012-04-30T11:21:08.987 に答える
1
StreamReader objReader = new StreamReader("c:\\test.txt");
string sLine="";
List<string> lstText = new List<string>();
while (sLine != null)
{
// Line by line read and add it to your List
sLine = objReader.ReadLine();
if (sLine != null)
lstText.Add(sLine);
}
objReader.Close();
foreach (string sOutput in arrText)
Console.WriteLine(sOutput);
Console.ReadLine();
以下のリンクに従ってください
于 2012-04-30T11:21:40.637 に答える