Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

property file

Posted on 2006-11-23
2
Medium Priority
?
213 Views
Last Modified: 2013-11-26
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)?
0
Comment
Question by:Rahamathulla_J
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
sivachirravuri earned 1000 total points
ID: 18006127
Hi,

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
sr.Close();
 
}
}
 
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> ");
return;
}
// 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
return;
}
 
FileRead fr = new FileRead();
try
{
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
 
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question