|
Il presente articolo è stato tradotto automaticamente. Passare il puntatore sulle frasi nell'articolo per visualizzare il testo originale. Ulteriori informazioni.
|
Traduzione
Originale
|
Procedura: leggere testo da un file
using System; using System.IO; class Test { public static void Main() { try { using (StreamReader sr = new StreamReader("TestFile.txt")) { String line = sr.ReadToEnd(); Console.WriteLine(line); } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } } }
using System; using System.Windows; using System.IO; namespace WpfApplication { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private async void ReadFileButton_Click(object sender, RoutedEventArgs e) { try { using (StreamReader sr = new StreamReader("TestFile.txt")) { String line = await sr.ReadToEndAsync(); ResultBlock.Text = line; } } catch (Exception ex) { ResultBlock.Text = "Could not read the file"; } } } }