You can accept the file name in the command line (along with path) and open the file in your application, read it line by line and process all the lines.
If you intend to give your program data program.exe < data.txt, this is called reading from standard input. You can do this via .NET's Console.OpenStandardInput with
new StreamReader(Console.OpenStandardInput())
Alternatively, if you'd rather your program be run program.exe data.txt, start with
Go to Solution Explorer > Right click on project file > Select Properties from context menu. This opens the properties window of the project. Now Go to Debug tab > Go to Start options section in right pane. Put the full file path inside Command line arguments text box as shown below:
< "D:\Rasik\input01.txt"
Then you can write code as usual and you will start getting input from the file:
class Program
{
static void Main(string[] args)
{
var textInFirstLineOfFile = Console.ReadLine();
}
}
You can accept the file name in the command line (along with path) and open the file in your application, read it line by line and process all the lines.
If you intend to give your program data
program.exe < data.txt
, this is called reading from standard input. You can do this via .NET's Console.OpenStandardInput withAlternatively, if you'd rather your program be run
program.exe data.txt
, start withGo to
Solution Explorer
>Right click on project file
>Select Properties from context menu
. This opens the properties window of the project. Now Go toDebug tab
> Go toStart options section
in right pane. Put the full file path insideCommand line arguments
text box as shown below:Then you can write code as usual and you will start getting input from the file: