how to run line by line in text file - on windows mobile?
in WinForm on PC i use to run like this:
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());
}
but when i try this on Windows-mobile i get error:
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?)
how to do it ?
thanks
If you want to read something use a Reader not a Writer
As has been mentioned, you're using a streamwriter not a streamreader
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);
}
}
You mean something like this?
using (var reader = File.OpenText("\\items.txt"))
{
while(reader.Peek() > 0)
{
var line = reader.ReadLine();
// do something with the line here
}
}
I can't see how the code you have would work even on the desktop, since neither ReadLine nor Peek even exist on a StreamWriter.
Try this, Read all the data in a string. Then split the string using the \n and then read each value in a string array.
精彩评论