[Mono-dev] Read file under Linux?
SamHellawell
samlikeswilly at live.co.uk
Thu Aug 5 13:39:55 EDT 2010
Hey there!
Basically, my C# project works perfectly well under Windows, and after
sorting out some GAC problems it *almost* works on Linux. I am stump however
as to how to open and read a file under Linux using Mono, i have tried
entering Linux paths and local paths. The file I wish to read is within the
same directly as the binary. If anybody could help me out, i'd greatly
appreciate it. The file i wish to load is called example.properties
My load function:
public Boolean Load(string filename)
{
try
{
FileStream file = File.Open(filename, FileMode.Open);
UTF8Encoding temp = new UTF8Encoding(true);
string fileContents = "";
byte[] b = new byte[1024];
while (file.Read(b, 0, b.Length) > 0)
{
fileContents += temp.GetString(b);
}
string[] lineSplit = fileContents.Split((char)10);
for(int i = 0; i < lineSplit.Length; i++)
{
props.Add(lineSplit[i].Split('=')[0],
lineSplit[i].Split('=')[1]);
}
return true;
}
catch
{
Console.WriteLine("Unable to load properties file: " +
filename);
return false;
}
}
Cheers, Sam.
--
View this message in context: http://mono.1490590.n4.nabble.com/Read-file-under-Linux-tp2315366p2315366.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
More information about the Mono-devel-list
mailing list