property file

I have to use java equivalent property files in c# to match a number in that file then display the corresponding string related to that number?

How can i do that in c# (Property file)?
Who is Participating?
sivachirravuriConnect With a Mentor Team Lead Commented:

This program just demonstrate the use of FileStream & StreamReader. Tthe program take 1 parameter from the user i.e. the file to read.  

Sample Code

using System;
using System.IO;
class FileRead
string filereadbuf; // buffer to store the content of file
public void ReadFile(string FileName, int FileSize)
char[] buf = new char[FileSize]; // lets define an array of type char field (i.e. variable) buf
// for more help please see .net sdk
StreamReader sr = new StreamReader(new FileStream(FileName, FileMode.Open, FileAccess.Read));
int retval = sr.ReadBlock(buf, 0, FileSize); // no. of bytes read
Console.Write ("Total Bytes Read = " + retval + "\n");
filereadbuf = new string(buf); // store it in our field
Console.WriteLine (filereadbuf); // lets print on screen
class TestFileRead
public static void Main(string[] args)
String[] cmdline = Environment.GetCommandLineArgs(); // Get the command line parameter
Console.WriteLine("File Reader Using Stream Reader & File Stream \n");
if (cmdline.Length < 2) // If no parameter is given will show user the usage
Console.WriteLine("Usage: " + cmdline[0] + " <input file> ");
// Using Directory Class & using a Method GetFiles we get file list from the current directory
// return value is array of files please see .net sdk documentation for more help.
File[] fe = (new Directory(".")).GetFiles(cmdline[1]);
if (fe.Length == 0)
Console.WriteLine(cmdline[1] + ": file not found"); // if not found display a message to user
FileRead fr = new FileRead();
fr.ReadFile(cmdline[1], (int)fe[0].Length); // sends 2 parameter filename & length
catch(IOException e){
Console.WriteLine("I/O error occured" + e);
return ;
} // Close brace of Main
} // close brace of TestFileRead
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.