Monday, November 9, 2015

Data input and save and output (using a .txt file)

I don't know how to close the external application so it keeps open...

This is incomplete version but there is a complete version.
code:

using System;
using System.Text;
using System.IO;
public class Sample2 {
  public static void Main(string[] args) {
        bool isSecond = false;
        string path ="";
        while(true){
         if(!isSecond){
          Console.Write("Give me a path for the text file.\n");
          path = Console.ReadLine();
         }
        Encoding enc = Encoding.GetEncoding("Shift_JIS");
        StreamReader sr = new StreamReader(path, enc);
        string text = sr.ReadToEnd();
        sr.Close();
        Console.Write("Saved data: \n" + text);
        Console.Write("Write something: \n");
        System.Diagnostics.Process.Start(@path);
   
        StreamWriter writer = new StreamWriter(@path, true, enc);
        string word = Console.ReadLine();    
   
        writer.WriteLine(word);
        Console.Write("Saved it\n");
        writer.Close();
        isSecond = true;
        }
  }
}