2011-01-06 5 views
0
PC에서의 WinForm에서

내가 이렇게 실행하는 데 사용 :텍스트 파일에서 줄 단위로 실행하는 방법 - Windows Mobile에서?

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()); 
} 

하지만 난 윈도우 모바일에이를하려고 할 때 오류 얻을 :

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?) 

방법을 수행하는 방법을?

감사

답변

1

으로는 파일이 큰 경우가 아닌 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); 
       } 
      } 
+0

도움을 주셔서 감사합니다, 어떻게 이것을 데이터 셋에 삽입 할 수 있습니까? – Gold

+0

@Gold 파일 형식을 알지 못하고 실제로 도움이되지 않습니다. – Robb

4

당신이 뭔가가 리더가 아닌 작가를 사용하여 읽을

1

당신이 뭔가를 의미하고 싶다면?

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

나는 당신이 코드에서는 ReadLine도 있기 때문에, 심지어 바탕 화면에서 작업하거나 심지어 StreamWriter에 존재 들여다 얼마나 볼 수 없습니다.

0

시도해보십시오. 문자열의 모든 데이터를 읽으십시오. 그런 다음 \ n을 사용하여 문자열을 분할 한 다음 문자열 배열의 각 값을 읽습니다.

+1

, 이것은 아마 아주 좋은 생각이 아니다 당신이 streamwriter을 사용하고, 언급하고있다. – ctacke

+0

모바일 장치 용으로, 내가 생각한 이유가 그 것이다. –

관련 문제