下面这段代码是用来调用.txt-file
并将其转换为字符串的代码。
string[] lines = System.IO.File.ReadAllLines(@"C:\This PC\Documents\Visual Studio 2015\Projects\test_read_txt\bin\Debug\read.txt");
为什么 C# 不能识别 的位置.txt-file
?我试过了,StreamReader
但后来无法修改读取。
class Program
{
static void Main(string[] args)
{
// Define our one and only variable
string[] M = new string[13];
// Read the text from the text file, and insert it into the array
StreamReader SR = new StreamReader(@"read.txt");
for (int i = 0; i < 13; i++)
{
M[i] = SR.ReadLine();
}
// Close the text file, so other applications/processes can use it
SR.Close();
// Write the array to the Console
Console.WriteLine("The array from the txt.file: ");
for (int i = 0; i < 13; i++)
{
Console.WriteLine(M[i]); // Displays the line to the user
}
// Pause the application so the user can read the information on the screen
Console.ReadLine();
if (2 == 2)
{
M[1][1] = 1;
}
}
}
它没有将其识别M[1][1]
为第二个数组的第二个元素,因为它只读取文件并没有将其转换为多维数组。以下代码可以用于上述问题吗?
tring[] lines = System.IO.File.ReadAllLines(@"C:\This PC\Documents\Visual Studio 2015\Projects\test_read_txt\bin\Debug\read.txt");