How to read a text file in project's root directory?

前端 未结 7 814
走了就别回头了
走了就别回头了 2020-12-04 10:45

I want to read the first line of a text file that I added to the root directory of my project. Meaning, my solution explorer is showing the .txt file along side my .cs files

7条回答
  •  不知归路
    2020-12-04 11:17

    In this code you access to root directory project:

     string _filePath = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory);
    

    then:

    StreamReader r = new StreamReader(_filePath + "/cities2.json"))
    

提交回复
热议问题