2011-01-12 200 views
0

我已经在“汽车”文件中创建了IO 中的一些文件,我想把一些其他参考如模型,颜色等...... 所以我的问题是:是有可能有在IO 多衬里的文件,如果是我怎样才能在StreamReader的 让他们//我想在一个文件中存储的许多参数,并通过StreamReaderIsolatedStorage @Windows Phone 7

保护覆盖无效找回来OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) {

  //reception des parametres de la listbox 
      base.OnNavigatedTo(e); 
      string parameter = this.NavigationContext.QueryString["parameter"]; 
      this.tbTitre.Text = parameter; 
      try 
      { 
       //Create a new StreamReader 
       StreamReader editionDevisReader = null; 
       IsolatedStorageFile probyOrange = IsolatedStorageFile.GetUserStoreForApplication(); 
       //Read the file from the specified location. 
       editionDevisReader = new StreamReader(new IsolatedStorageFileStream("devis\\"+parameter+".txt", FileMode.Open, probyOrange)); 
       //Read the contents of the file . 
       string textFile = editionDevisReader.ReadLine(); 

       //Write the contents of the file to the TextBlock on the page. 
       tbTitre.Text = textFile; 

       while (editionDevisReader != null) 
       { 
        RowDefinition rowdefinition = new RowDefinition(); 

        TextBlock textblock = new TextBlock(); 
        textblock.HorizontalAlignment = new System.Drawing.Size(48, 20); 

       } 
       editionDevisReader.Close(); 
      } 
      catch 
      { 
       //If the file hasn't been created yet. 
       tbTitre.Text = "veuillez d abord creer le fichier"; 
      } 

THX很多都

回答

1

是的,你可以在一个文件中保存任何东西(最高点):

using (var store = IsolatedStorageFile.GetUserStoreForApplication()) 
{ 
    using (var isfs = new IsolatedStorageFileStream("myfile.txt", FileMode.OpenOrCreate, store)) 
    { 
     using (var sw = new StreamWriter(isfs)) 
     { 
      sw.Write("anything really. Here it's just a string but could be a serialized object, etc."); 
      sw.Close(); 
     } 
    } 
} 

然后,您可以读取该文件:

var result = string.Empty; 

try 
{ 
    using (var store = IsolatedStorageFile.GetUserStoreForApplication()) 
    { 
     if (!store.FileExists("myfile.txt")) 
     { 
      return result; 
     } 

     using (var isfs = new IsolatedStorageFileStream("myfile.txt", FileMode.Open, store)) 
     { 
      using (var sr = new StreamReader(isfs)) 
      { 
       string lineOfData; 

       while ((lineOfData = sr.ReadLine()) != null) 
       { 
        result += lineOfData; 
       } 
      } 
     } 
    } 
} 
catch (IsolatedStorageException) 
{ 
    result = string.Empty; // may have partial data/file before error 
} 

return result; 
+0

我明白了,我想知道如何在streamreader中读取它们。如果我创建一个文件“car.txt”,我想在文件中加入颜色,模型等......所以我怎么读它们? thx很多为你的帮助 – user569574 2011-01-12 13:53:38

+0

@ user569574我已经添加了一个阅读文件的例子 – 2011-01-13 09:15:05

0

你可以使用

StreamReader.Writeline 

StreamRead.ReadLine 

写入和读取由换行符分隔的文本块。