2010-12-29 5 views

Antwort

3

Windows Mobile 6.5, wie schreiben/Text in einer Datei liest ein Etikett (label1) stecken in Entwurfsansicht fügen Sie die folgenden Zeilen im Code


Code:

 string path = "\\test.txt";//file Loc: *start->file explorer->text.txt* 
     if (!File.Exists(path)) 
     { 
      using (StreamWriter sw = File.CreateText(path)) 
      { 
       sw.WriteLine("Hello"); 
       sw.WriteLine("And"); 
       sw.WriteLine("Welcome"); 
      } 
     } 
     using (StreamReader sr = File.OpenText(path)) 
     { 
      string s = ""; 

      label1.Text = ""; 
      while ((s = sr.ReadLine()) != null) 
      { 
       label1.Text += s; 
      } 
     } 
0

in eine Datei zu schreiben,

 FileInfo fi = new FileInfo(Path+"\\txtServer.inf");//\\Application 
     using (TextWriter txtWriter = new StreamWriter(fi.Open(FileMode.Truncate))) 
     { 
      txtWriter.WriteLine("Hello"); 

     } 

aus der Datei lesen

string path = Path + "\\txtServer.inf";//\\Application 

    if (!File.Exists(path)) 
     { 
      using (StreamWriter sw = File.CreateText(path)) 
      { 

      } 
     } 
     else 
     { 
      using (StreamReader sr = File.OpenText(path)) 
      { 
       string s = ""; 
       Label1.Text =""; 

       while ((s = sr.ReadLine()) != null) 
       { 
        Label1.Text = s; 
       } 
      } 
     } 
Verwandte Themen