Как запустить построчно в текстовом файле - на Windows Mobile? - PullRequest
0 голосов
/ 06 января 2011

в WinForm на ПК, который я использую для запуска следующим образом:

FileStream FS = null;
StreamWriter SW = null;
FS = new FileStream(@"\Items.txt", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
SW = new StreamWriter(FS, Encoding.Default);
while (SW.Peek() != -1)
{
   TEMP = (SW.ReadLine());
}

но когда я пробую это на Windows-Mobile, я получаю сообщение об ошибке:

Error   1   'System.IO.StreamWriter' does not contain a definition for 'Peek' and no extension method 'Peek' accepting a first argument of type 'System.IO.StreamWriter' could be found (are you missing a using directive or an assembly reference?)
Error   2   'System.IO.StreamWriter' does not contain a definition for 'ReadLine' and no extension method 'ReadLine' accepting a first argument of type 'System.IO.StreamWriter' could be found (are you missing a using directive or an assembly reference?)

как это сделать?

спасибо

Ответы [ 4 ]

4 голосов
/ 06 января 2011

Если вы хотите что-то прочитать, используйте Reader, а не Writer

1 голос
/ 07 января 2011

Как уже упоминалось, вы используете потоковый писатель , а не потоковый читатель

using (StreamReader sr = new StreamReader("TestFile.txt")) 
            {
                string line;
                // Read and display lines from the file until the end of 
                // the file is reached.
                while ((line = sr.ReadLine()) != null) 
                {
                    Console.WriteLine(line);
                }
            }
1 голос
/ 06 января 2011

Вы имеете в виду что-то подобное?

using (var reader = File.OpenText("\\items.txt"))
{
    while(reader.Peek() > 0)
    {
        var line = reader.ReadLine();
        // do something with the line here
    }
}

Я не вижу, как ваш код будет работать даже на настольном компьютере, поскольку ни ReadLine, ни Peek даже не существуют на StreamWriter .

0 голосов
/ 07 января 2011

Попробуйте, прочитайте все данные в строке. Затем разбейте строку, используя \ n, и затем прочитайте каждое значение в массиве строк.

...